Running Aspire and Seeing Connection failure from the App Host when starting up.

Trent Whiteley 0 Reputation points
2025-06-26T12:35:18.5+00:00

My program.cs is below. When I start the app up with the container creation commented out everything comes up fine. Uncomment it and I get the error, Failed to connect to 127.0.0.1:9712. I know that is the Cosmos DB. The dashboard that comes up with Aspire shows that both the database and the container are healthy (see below). However, if I select the Data Explorer, it shows no container has been created and fails in the same way if I try to create a container manually.

User's image

User's image

User's image

using Projects;

var builder = DistributedApplication.CreateBuilder(args);

var secrets = builder.ExecutionContext.IsPublishMode

? builder.AddAzureKeyVault("secrets")

: builder.AddConnectionString("key-vault");

var insights = builder.AddConnectionString("myInsightsResource");

var storage = builder.AddAzureStorage("storage").RunAsEmulator()

.AddBlobs("blobs");

var cache = builder.AddAzureRedis("cache").RunAsContainer();

var sql = builder.AddSqlServer("sql")

.WithDataVolume()

.WithLifetime(ContainerLifetime.Persistent);

var sqlDb = sql.AddDatabase("sqldatabase");

var sqlDbManager = builder.AddProject<F22_Core_Data_SqlDatabaseManager>("sqldbmanager")

.WithReference(sqlDb)

.WaitFor(sqlDb);

#pragma warning disable ASPIRECOSMOSDB001

var cosmos = builder.AddAzureCosmosDB("cosmos-db")

.RunAsPreviewEmulator(p => p.WithDataExplorer().WithDataVolume().WithLifetime(ContainerLifetime.Persistent));

var tenantData = cosmos.AddCosmosDatabase("tenant")

.AddContainer("tenantData", "/id");

//var userData = cosmos.AddCosmosDatabase("user")

// .AddContainer("userData", "/id");

#pragma warning restore ASPIRECOSMOSDB001

var prototype = builder.AddProject<F22_Services_PrototypeService>("prototype")

.WithReference(insights)

.WithReference(cache)

.WaitFor(cache)

.WithReference(sqlDb)

.WaitFor(sqlDbManager)

.WaitFor(cosmos)

.WithReference(cosmos);

builder.AddProject<F22_Client_Web>("webfrontend")

.WithExternalHttpEndpoints()

.WithReference(storage)

.WithReference(secrets)

.WithReference(cache)

.WaitFor(cache)

.WithReference(prototype)

.WaitFor(prototype)

.WithReference(insights);

builder.Build().Run();

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
{count} votes

1 answer

Sort by: Most helpful
  1. Trent Whiteley 0 Reputation points
    2025-06-26T19:05:10.9333333+00:00

    As my question stated, everything comes up fine if I don't create a container at startup. However, bringing up the Cosmos dashboard and attempting to manually create a container fails with the same message. This was all running fine before the 9.3.1 Aspire update after which it started failing. I've already checked and there are no other processes using that port and the AppHost is already waiting on the Cosmos DB to start up.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.