{"record":{"id":"c5ae66056bbd287b","repo":"microsoft/aspire","slug":"nameof-connectionstringavailableevent-was-published-for-the","errorCode":null,"errorMessage":"{nameof(ConnectionStringAvailableEvent)} was published for the '{builder.Resource.Name}' resource but the connection string was null.","messagePattern":"(.+?) was published for the '(.+?)' resource but the connection string was null\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs","lineNumber":218,"sourceCode":"               .WithHttpEndpoint(name: \"table\", targetPort: 10002)\n               .WithAnnotation(new ContainerImageAnnotation\n               {\n                   Registry = StorageEmulatorContainerImageTags.Registry,\n                   Image = StorageEmulatorContainerImageTags.Image,\n                   Tag = StorageEmulatorContainerImageTags.Tag\n               });\n\n        BlobServiceClient? blobServiceClient = null;\n        QueueServiceClient? queueServiceClient = null;\n\n        builder\n            .OnBeforeResourceStarted(async (storage, @event, ct) =>\n            {\n                // The BlobServiceClient and QueueServiceClient are created before the health check is run.\n                // We can't use ConnectionStringAvailableEvent here because the resource doesn't have a connection string, so\n                // we use BeforeResourceStartedEvent\n\n                var blobConnectionString = await builder.Resource.GetBlobConnectionString().GetValueAsync(ct).ConfigureAwait(false) ?? throw new DistributedApplicationException($\"{nameof(ConnectionStringAvailableEvent)} was published for the '{builder.Resource.Name}' resource but the connection string was null.\");\n                blobServiceClient = CreateBlobServiceClient(blobConnectionString);\n\n                var queueConnectionString = await builder.Resource.GetQueueConnectionString().GetValueAsync(ct).ConfigureAwait(false) ?? throw new DistributedApplicationException($\"{nameof(ConnectionStringAvailableEvent)} was published for the '{builder.Resource.Name}' resource but the connection string was null.\");\n                queueServiceClient = CreateQueueServiceClient(queueConnectionString);\n            })\n            .OnResourceReady(async (storage, @event, ct) =>\n            {\n                // The ResourceReadyEvent of a resource is triggered after its health check (AddAzureBlobStorage) is healthy.\n                // This means we can safely use this event to create the blob containers.\n\n                _ = blobServiceClient ?? throw new InvalidOperationException($\"{nameof(BlobServiceClient)} is not initialized.\");\n                _ = queueServiceClient ?? throw new InvalidOperationException($\"{nameof(QueueServiceClient)} is not initialized.\");\n\n                foreach (var container in builder.Resource.BlobContainers)\n                {\n                    var blobContainerClient = blobServiceClient.GetBlobContainerClient(container.BlobContainerName);\n                    await blobContainerClient.CreateIfNotExistsAsync(cancellationToken: ct).ConfigureAwait(false);\n                }","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs#L200-L236","documentation":"In RunAsEmulator's OnBeforeResourceStarted handler, the blob connection string is resolved asynchronously; if it resolves to null the code throws DistributedApplicationException referencing ConnectionStringAvailableEvent. This is an internal invariant: without a connection string the emulator's BlobServiceClient cannot be created.","triggerScenarios":"Resource start of an emulated Azure Storage resource where GetBlobConnectionString().GetValueAsync returns null (connection string expression produced no value).","commonSituations":"Emulator endpoint/proxy not correctly configured, misconfigured emulator settings, or internal wiring regression causing a missing connection string at startup.","solutions":["Check the emulator container started correctly and its endpoint was published","Re-run with updated Aspire packages; if it persists, file an issue (this indicates an internal invariant failure)","Verify RunAsEmulator configuration (port assignments, proxy settings) is unchanged"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"var cs = await storage.Resource.GetBlobConnectionString().GetValueAsync(ct);\nif (cs is null) { logger.LogError(\"Blob connection string missing for {Name}\", storage.Resource.Name); return; }","typeGuard":null,"tryCatchPattern":"try { await startWorkflow(ct); }\ncatch (DistributedApplicationException ex) { logger.LogError(ex, \"Emulator connection string invariant failed\"); throw; }","preventionTips":["Keep RunAsEmulator wiring on current Aspire versions","Do not remove lifecycle hooks that initialize emulator clients","Verify emulator endpoints publish before resource start"],"tags":["azure","storage","emulator","connection-string","invariant"],"backgroundTag":"internal-invariant-violation","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"}