microsoft/aspire · error · DistributedApplicationException
ConnectionStringAvailableEvent published for resource
Error message
ConnectionStringAvailableEvent published for resource '{db.Name}', but the connection string was null. What it means
AzureKustoBuilderExtensions registers a handler for the ConnectionStringAvailableEvent on the Kusto database resource. The handler resolves the resource's ConnectionStringExpression; a null result is impossible under normal eventing invariants (the event means a connection string is available), so a null is surfaced as a DistributedApplicationException naming the resource. It also assigns the parsed KustoConnectionStringBuilder for the subsequent health check.
Solutions
- Ensure the parent AddAzureKustoCluster resource is configured so it supplies a connection string to its databases.
- If overriding ConnectionString via WithConnectionString/callback, guarantee it returns a non-null value (e.g. a valid Kusto connection string).
- Check for model mutations (removing the cluster or clearing its connection string) before the database resource runs.
- In tests, do not publish ConnectionStringAvailableEvent manually without setting the connection string.
Example fix
// before
.WithConnectionString(_ => null) // handler gets null
// after
.WithConnectionString("Data Source=https://mycluster.kusto.windows.net;...") Defensive patterns
Strategy: type-guard
Validate before calling
var cs = await db.ConnectionStringExpression.GetValueAsync(ct);
if (cs is null)
throw new InvalidOperationException("Kusto connection string was not populated; check the parent cluster resource configuration."); Type guard
string? GuardConnectionString(object? value) => value as string is { Length: > 0 } s ? s : null; Try / catch
try { await StartAsync(); }
catch (DistributedApplicationException ex) when (ex.Message.Contains("connection string was null"))
{
// fix the cluster resource / connection-string override before retry
} Prevention
- Never override ConnectionString with a callback that can return null
- Verify the parent Kusto cluster resource is fully configured
- In tests, only publish ConnectionStringAvailableEvent after setting the connection string
When it happens
Trigger: The OnConnectionStringAvailable callback fires for the Kusto database and db.ConnectionStringExpression.GetValueAsync(ct) returns null - e.g. the connection string callback was never populated because the parent Kusto cluster resource is misconfigured, a custom ConnectionString override returns null, or the resource model was mutated before the event fired.
Common situations: Manually overriding the connection string with a callback that returns null; using the database resource without a properly configured cluster resource; tests or custom host code publishing ConnectionStringAvailableEvent without actually setting the connection string.
Related errors
- A BlobServiceClient could not be configured. Ensure valid…
- A BlobServiceClient could not be configured. Ensure valid…
- A ChatCompletionsClient could not be configured. Ensure…
- A CosmosClient could not be configured. Ensure valid…
- A DataLakeServiceClient could not be configured. Ensure…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/1abfbeb1fb77aa2f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Kusto/AzureKustoBuilderExtensions.cs:128
public static IResourceBuilder<AzureKustoReadWriteDatabaseResource> AddReadWriteDatabase(this IResourceBuilder<AzureKustoClusterResource> builder, [ResourceName] string name, string? databaseName = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrWhiteSpace(name);
// Use the resource name as the database name if it's not provided
databaseName ??= name;
var kustoDatabase = new AzureKustoReadWriteDatabaseResource(name, databaseName, builder.Resource);
builder.Resource.Databases.Add(kustoDatabase);
var resourceBuilder = builder.ApplicationBuilder.AddResource(kustoDatabase)
.WithIconName("Database");
// Register a health check that will be used to verify database is available
KustoConnectionStringBuilder? kcsb = null;
resourceBuilder.OnConnectionStringAvailable(async (db, evt, ct) =>
{
var connectionString = await db.ConnectionStringExpression.GetValueAsync(ct).ConfigureAwait(false) ??
throw new DistributedApplicationException($"ConnectionStringAvailableEvent published for resource '{db.Name}', but the connection string was null.");
kcsb = GetConnectionStringBuilder(builder.Resource, connectionString);
});
var healthCheckKey = $"{kustoDatabase.Name}_check";
resourceBuilder.ApplicationBuilder
.Services
.AddHealthChecks()
.AddAzureKustoHealthCheck(healthCheckKey, isCluster: false, _ => kcsb!);
resourceBuilder
.WithHealthCheck(healthCheckKey);
return resourceBuilder;
}
/// <summary>
/// Configures the Kusto resource to run as an emulator using the Kustainer container.View on GitHub (pinned to 25830f84bd)