{"record":{"id":"f9dd238512d72f87","repo":"microsoft/aspire","slug":"connectionstringavailableevent-published-for-resource","errorCode":null,"errorMessage":"ConnectionStringAvailableEvent published for resource '{resource.Name}', but the connection string was null.","messagePattern":"ConnectionStringAvailableEvent published for resource '(.+?)', but the connection string was null\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Kusto/AzureKustoBuilderExtensions.cs","lineNumber":243,"sourceCode":"        return builder.WithEndpoint(\"http\", endpoint =>\n        {\n            endpoint.Port = port;\n        });\n    }\n\n    /// <summary>\n    /// Adds Kusto-specific health checks and lifecycle management.\n    /// </summary>\n    private static void AddKustoHealthChecksAndLifecycleManagement(IResourceBuilder<AzureKustoClusterResource> resourceBuilder)\n    {\n        var resource = resourceBuilder.Resource;\n\n        // Register a health check that will be used to verify Kusto is available\n        KustoConnectionStringBuilder? kcsb = null;\n        resourceBuilder.OnConnectionStringAvailable(async (resource, evt, ct) =>\n        {\n            var connectionString = await resource.ConnectionStringExpression.GetValueAsync(ct).ConfigureAwait(false) ??\n            throw new DistributedApplicationException($\"ConnectionStringAvailableEvent published for resource '{resource.Name}', but the connection string was null.\");\n\n            kcsb = GetConnectionStringBuilder(resource, connectionString);\n        });\n\n        var healthCheckKey = $\"{resource.Name}_check\";\n        resourceBuilder.ApplicationBuilder\n            .Services\n            .AddHealthChecks()\n            .AddAzureKustoHealthCheck(healthCheckKey, isCluster: true, _ => kcsb!);\n\n        // Execute any setup now that Kusto is ready\n        resourceBuilder.OnResourceReady(async (server, evt, ct) =>\n        {\n            if (kcsb is null)\n            {\n                throw new DistributedApplicationException($\"Connection string for Kusto resource '{server.Name}' is not set.\");\n            }\n","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Kusto/AzureKustoBuilderExtensions.cs#L225-L261","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar kusto = builder.AddAzureKustoCluster(\"kusto\")\n    .WithConnectionString(null);\n// after\nvar kusto = builder.AddAzureKustoCluster(\"kusto\")\n    .WithConnectionString(builder.AddParameter(\"kusto-connection-string\"));","handlingStrategy":"validation","validationCode":"var cs = await resource.ConnectionStringExpression.GetValueAsync(ct);\nif (string.IsNullOrEmpty(cs)) throw new InvalidOperationException($\"Kusto resource '{resource.Name}' has no connection string; check its backing parameter/config.\");","typeGuard":"if (resource.ConnectionStringExpression is null) { /* resource has no connection string source configured */ }","tryCatchPattern":null,"preventionTips":["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."],"tags":["aspire","azure-kusto","connection-string","orchestration"],"backgroundTag":"missing-config-value","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}