microsoft/aspire · error · DistributedApplicationException
Connection string for Kusto resource
Error message
Connection string for Kusto resource '{server.Name}' is not set. What it means
When the Kusto resource signals it is ready, Aspire's lifecycle hook checks that the KustoConnectionStringBuilder captured during the ConnectionStringAvailableEvent (kcsb) is non-null. If the earlier event callback never ran successfully, the OnResourceReady callback throws this DistributedApplicationException because database creation and setup cannot proceed without a parsed connection string.
Solutions
- Verify the resource obtains a connection string before becoming ready; check that WithConnectionString or the emulator configuration supplies a value.
- Confirm no custom code unsubscribes or short-circuits OnConnectionStringAvailable callbacks.
- Check the AppHost logs for an earlier ConnectionStringAvailable error that left kcsb unset.
- If using RunAsEmulator, ensure the emulator resource resolves its connection string (container started and endpoint known).
Defensive patterns
Strategy: validation
Validate before calling
if (await server.ConnectionStringExpression.GetValueAsync(ct) is null) throw new InvalidOperationException("Kusto connection string must resolve before the resource becomes ready."); Type guard
if (kcsb is null) { /* connection string event never completed; fail fast before Ready work */ } Prevention
- Keep the default OnConnectionStringAvailable hook intact; don't replace callbacks that set up the connection string.
- Confirm connection string sources resolve before the resource signals Ready.
- Avoid custom lifecycle code that bypasses connection string events.
- Check AppHost logs for earlier connection string errors when this one appears.
When it happens
Trigger: OnResourceReady fires but kcsb is null — this happens when the ConnectionStringAvailableEvent callback never executed or did not set kcsb, e.g. the connection string event never fired for the Kusto resource or the connection string was null at that stage.
Common situations: Resource transitions to Ready state before the connection string event completed, a custom host setup suppresses connection string events, or emulator/Azure mode switching left the connection string unset.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Connection string for Kusto resource
- ConnectionStringAvailableEvent published for resource
- Connection string is unavailable
- Connection string is unavailable
- Connection string is unavailable
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/9be7258ac8873987.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Kusto/AzureKustoBuilderExtensions.cs:259
{
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.");
}
if (!server.IsEmulator)
{
// We only support automatic database creation when running as an emulator.
// When running in Azure, the databases will be created as part of the provisioning process.
return;
}
using var adminProvider = KustoClientFactory.CreateCslAdminProvider(kcsb);
foreach (var kustoDatabase in server.Databases)
{
await CreateDatabaseAsync(adminProvider, kustoDatabase, evt.Services, ct).ConfigureAwait(false);
}
});
resourceBuilder.WithHealthCheck(healthCheckKey);
}View on GitHub (pinned to 25830f84bd)