{"record":{"id":"01213c00004f5547","repo":"microsoft/aspire","slug":"connection-string-is-not-initialized","errorCode":null,"errorMessage":"Connection string is not initialized.","messagePattern":"Connection string is not initialized\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs","lineNumber":502,"sourceCode":"    [AspireExport]\n    public static IResourceBuilder<AzureBlobStorageContainerResource> AddBlobContainer(this IResourceBuilder<AzureStorageResource> builder, [ResourceName] string name, string? blobContainerName = null)\n    {\n        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentException.ThrowIfNullOrEmpty(name);\n\n        blobContainerName ??= name;\n\n        var parentBuilder = builder.Resource.ImplicitBlobService ??= GetBlobService(builder);\n        AzureBlobStorageContainerResource resource = new(name, blobContainerName, parentBuilder.Resource);\n        builder.Resource.BlobContainers.Add(resource);\n\n        string? connectionString = null;\n\n        var healthCheckKey = $\"{resource.Name}_check\";\n\n        BlobServiceClient? blobServiceClient = null;\n        builder.ApplicationBuilder.Services.AddHealthChecks().AddAzureBlobStorage(\n            sp => blobServiceClient ??= CreateBlobServiceClient(connectionString ?? throw new InvalidOperationException(\"Connection string is not initialized.\")),\n            optionsFactory: sp => new HealthChecks.Azure.Storage.Blobs.AzureBlobStorageHealthCheckOptions { ContainerName = blobContainerName },\n            name: healthCheckKey);\n\n        return builder.ApplicationBuilder\n            .AddResource(resource)\n            .WithIconName(\"FolderOpen\")\n            .WithHealthCheck(healthCheckKey)\n            .OnConnectionStringAvailable(async (containerResource, @event, ct) =>\n            {\n                connectionString = await resource.Parent.ConnectionStringExpression.GetValueAsync(ct).ConfigureAwait(false);\n            });\n    }\n\n    /// <summary>\n    /// Creates a builder for the <see cref=\"AzureDataLakeStorageFileSystemResource\"/> which can be referenced to get the Azure DataLake file system connection string.\n    /// </summary>\n    /// <ats-summary>Adds an Azure Data Lake Storage file system resource</ats-summary>\n    /// <param name=\"builder\">The <see cref=\"IResourceBuilder{T}\"/> for <see cref=\"AzureStorageResource\"/>.</param>","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs#L484-L520","documentation":"AddBlobContainer registers a health check that lazily creates a BlobServiceClient from a connection string captured via a callback. The `connectionString ?? throw` guard fires when the connection-string resolution callback never assigned a value, meaning the resource was never bound to a real storage connection.","triggerScenarios":"Calling builder.AddBlobContainer(...) on a resource whose ConnectionStringResource / connection string callback returned null when the health check factory executed.","commonSituations":"Creating a blob container resource without a parent storage resource connection; referencing a storage resource that failed to start; typos in the referenced resource name so the callback never resolves.","solutions":["Call AddBlobContainer on a resource created via AddAzureStorage (or another storage resource with a valid connection string)","Ensure the parent storage resource is running and healthy before this health check executes","Check the connection string callback/reference wired to the resource returns a non-empty value"],"exampleFix":"// before\nvar blobs = builder.AddBlobContainer(\"container\", parent: unboundResource);\n// after\nvar storage = builder.AddAzureStorage(\"storage\");\nvar blobs = storage.AddBlobs(\"blobs\").AddBlobContainer(\"container\");","handlingStrategy":"validation","validationCode":"if (parentResource is null || parentResource.ConnectionStringResource is null)\n    throw new InvalidOperationException(\"Blob container parent must have a connection string resource.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always create blob containers as children of a properly connected storage resource","Ensure the storage parent runs before dependent health checks execute"],"tags":["azure-storage","connection-string","health-check","blob"],"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-21T09:17:21.228Z"}