{"record":{"id":"9be7258ac8873987","repo":"microsoft/aspire","slug":"connection-string-for-kusto-resource-server-name-is-not-set","errorCode":null,"errorMessage":"Connection string for Kusto resource '{server.Name}' is not set.","messagePattern":"Connection string for Kusto resource '(.+?)' is not set\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Kusto/AzureKustoBuilderExtensions.cs","lineNumber":259,"sourceCode":"        {\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\n            if (!server.IsEmulator)\n            {\n                // We only support automatic database creation when running as an emulator.\n                // When running in Azure, the databases will be created as part of the provisioning process.\n                return;\n            }\n\n            using var adminProvider = KustoClientFactory.CreateCslAdminProvider(kcsb);\n            foreach (var kustoDatabase in server.Databases)\n            {\n                await CreateDatabaseAsync(adminProvider, kustoDatabase, evt.Services, ct).ConfigureAwait(false);\n            }\n        });\n\n        resourceBuilder.WithHealthCheck(healthCheckKey);\n    }","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Kusto/AzureKustoBuilderExtensions.cs#L241-L277","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (await server.ConnectionStringExpression.GetValueAsync(ct) is null) throw new InvalidOperationException(\"Kusto connection string must resolve before the resource becomes ready.\");","typeGuard":"if (kcsb is null) { /* connection string event never completed; fail fast before Ready work */ }","tryCatchPattern":null,"preventionTips":["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."],"tags":["aspire","azure-kusto","connection-string","lifecycle"],"backgroundTag":"invalid-state-transition","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"}