microsoft/aspire · error · DistributedApplicationException
ConnectionStringAvailableEvent published for resource
Error message
ConnectionStringAvailableEvent published for resource '{resource.Name}', but the connection string was null. What it means
Aspire's Azure Kusto integration registers a callback on the ConnectionStringAvailableEvent that resolves the resource's connection string. If the event fires but the connection string expression resolves to null, the library throws this DistributedApplicationException because the health-check and lifecycle setup cannot proceed without a valid connection string.
Solutions
- Ensure the Kusto resource has a connection string: verify any backing parameter/configuration value (user-secrets, appsettings, environment) is set before running the AppHost.
- If wrapping an existing cluster with an explicit connection string, call WithConnectionString/with a non-null value so ConnectionStringExpression resolves.
- Check custom code that overrides the connection string expression and make sure it never returns null.
- Run with dashboard logs and inspect the resource model at the time of the event to confirm which source (parameter/reference) yielded null.
Example fix
// before
var kusto = builder.AddAzureKustoCluster("kusto")
.WithConnectionString(null);
// after
var kusto = builder.AddAzureKustoCluster("kusto")
.WithConnectionString(builder.AddParameter("kusto-connection-string")); Defensive patterns
Strategy: validation
Validate before calling
var cs = await resource.ConnectionStringExpression.GetValueAsync(ct);
if (string.IsNullOrEmpty(cs)) throw new InvalidOperationException($"Kusto resource '{resource.Name}' has no connection string; check its backing parameter/config."); Type guard
if (resource.ConnectionStringExpression is null) { /* resource has no connection string source configured */ } Prevention
- Always back Kusto connection strings with a parameter or explicit value at AppHost build time.
- Set user-secrets/config keys before running the AppHost.
- Use RunAsEmulator for local development so a connection string is guaranteed.
- Validate connection strings early with a startup check in the AppHost.
When it happens
Trigger: The OnConnectionStringAvailable callback fires for the Azure Kusto cluster resource but resource.ConnectionStringExpression.GetValueAsync returns null — e.g. the connection string was never assigned, a referenced parameter resolved to null, or a callback cleared the connection string before the event was published.
Common situations: Running an AppHost where the Kusto connection string is backed by a missing/empty configuration value (user-secrets or appsettings key not set), a RunAsEmulator misconfiguration, or code that overrode the connection string expression after AddAzureKustoCluster.
Understand the failure class
Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.
Related errors
- Connection string for Kusto resource
- Connection string for Kusto resource
- Circular dependency detected
- Connection string is unavailable
- Connection string is unavailable
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/f9dd238512d72f87.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Kusto/AzureKustoBuilderExtensions.cs:243
return builder.WithEndpoint("http", endpoint =>
{
endpoint.Port = port;
});
}
/// <summary>
/// Adds Kusto-specific health checks and lifecycle management.
/// </summary>
private static void AddKustoHealthChecksAndLifecycleManagement(IResourceBuilder<AzureKustoClusterResource> resourceBuilder)
{
var resource = resourceBuilder.Resource;
// Register a health check that will be used to verify Kusto is available
KustoConnectionStringBuilder? kcsb = null;
resourceBuilder.OnConnectionStringAvailable(async (resource, evt, ct) =>
{
var connectionString = await resource.ConnectionStringExpression.GetValueAsync(ct).ConfigureAwait(false) ??
throw new DistributedApplicationException($"ConnectionStringAvailableEvent published for resource '{resource.Name}', but the connection string was null.");
kcsb = GetConnectionStringBuilder(resource, connectionString);
});
var healthCheckKey = $"{resource.Name}_check";
resourceBuilder.ApplicationBuilder
.Services
.AddHealthChecks()
.AddAzureKustoHealthCheck(healthCheckKey, isCluster: true, _ => kcsb!);
// Execute any setup now that Kusto is ready
resourceBuilder.OnResourceReady(async (server, evt, ct) =>
{
if (kcsb is null)
{
throw new DistributedApplicationException($"Connection string for Kusto resource '{server.Name}' is not set.");
}
View on GitHub (pinned to 25830f84bd)