microsoft/aspire · error · DistributedApplicationException
ResourceReadyEvent was published for the
Error message
ResourceReadyEvent was published for the '{sqlServer.Name}' resource but the connection string was null. What it means
When the SQL Server resource signals ResourceReadyEvent, the integration expects the connection string captured in the earlier ConnectionStringAvailableEvent callback to be set. It opens a SqlConnection and creates any declared databases. If the connection string is still null at ResourceReady time, the ordering guarantee was violated and the integration throws DistributedApplicationException.
Solutions
- Check the dashboard/logs for a failure in the ConnectionStringAvailable step of this same resource; fixing that failure restores the expected ordering and removes this error.
- Do not replace or re-create the SqlServerServerResource builder/resource after AddSqlServer; always chain on the returned IResourceBuilder so its event handlers stay attached.
- Remove custom event subscriptions that could preempt or suppress the integration's OnConnectionStringAvailable handler for this resource.
- Update Aspire.Hosting.SqlServer if you suspect an eventing ordering regression; reproduce with a minimal AppHost to confirm.
Example fix
// before
var sqlServer = builder.AddSqlServer("sql");
var rebuilt = builder.CreateResourceBuilder(sqlServer.Resource); // detaches original event wiring
rebuilt.WithReference(...);
// after
var sqlServer = builder.AddSqlServer("sql");
sqlServer.WithReference(...); // chain on the original builder, preserving lifecycle event wiring Defensive patterns
Strategy: try-catch
Try / catch
try
{
// start/await resource lifecycle
}
catch (DistributedApplicationException ex) when (ex.Message.Contains("ResourceReadyEvent was published"))
{
// lifecycle ordering violated: check whether ConnectionStringAvailable handling failed earlier for this resource
} Prevention
- Treat this error as a symptom: fix the earlier ConnectionStringAvailable failure that left the connection string null.
- Do not subscribe custom lifecycle events that reorder or suppress the integration's handlers on the SQL Server resource.
- Always use the builder instance returned by AddSqlServer for subsequent configuration.
- After upgrading Aspire packages, verify resource startup end-to-end in run mode to catch eventing changes early.
When it happens
Trigger: OnResourceReady executes while the local connectionString variable is null: the ConnectionStringAvailable handler either never ran, threw before assigning (see the sibling null-check error), or event ordering was disturbed so ResourceReady fires without a prior ConnectionStringAvailable — typically caused by custom eventing, resource replacement, or an integration version regression.
Common situations: Custom AppHost code subscribing/reordering lifecycle events on the SQL Server resource; a resource builder or model transformation that re-created the resource and lost the earlier event wiring; debugging scenarios where the ConnectionStringAvailable callback failed silently earlier.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- ConnectionStringAvailableEvent was published for the
- ResourceReadyEvent was published for the
- Connection string for Kusto resource
- Connection string is unavailable
- ConnectionStringAvailableEvent was published for the
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/bf43908e4ac34f52.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.SqlServer/SqlServerBuilderExtensions.cs:77
.WithEnvironment(context =>
{
context.EnvironmentVariables["MSSQL_SA_PASSWORD"] = sqlServer.PasswordParameter;
})
.WithHealthCheck(healthCheckKey)
.OnConnectionStringAvailable(async (sqlServer, @event, ct) =>
{
connectionString = await sqlServer.GetConnectionStringAsync(ct).ConfigureAwait(false);
if (connectionString == null)
{
throw new DistributedApplicationException($"ConnectionStringAvailableEvent was published for the '{sqlServer.Name}' resource but the connection string was null.");
}
})
.OnResourceReady(async (sqlServer, @event, ct) =>
{
if (connectionString is null)
{
throw new DistributedApplicationException($"ResourceReadyEvent was published for the '{sqlServer.Name}' resource but the connection string was null.");
}
using var sqlConnection = new SqlConnection(connectionString);
await sqlConnection.OpenAsync(ct).ConfigureAwait(false);
if (sqlConnection.State != System.Data.ConnectionState.Open)
{
throw new InvalidOperationException($"Could not open connection to '{sqlServer.Name}'");
}
foreach (var sqlDatabase in sqlServer.DatabaseResources)
{
await CreateDatabaseAsync(sqlConnection, sqlDatabase, @event.Services, ct).ConfigureAwait(false);
}
});
}
/// <summary>View on GitHub (pinned to 25830f84bd)