microsoft/aspire · error · InvalidOperationException
Connection string is not initialized.
Error message
Connection string is not initialized.
What it means
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.
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
Example fix
// before
var blobs = builder.AddBlobContainer("container", parent: unboundResource);
// after
var storage = builder.AddAzureStorage("storage");
var blobs = storage.AddBlobs("blobs").AddBlobContainer("container"); Defensive patterns
Strategy: validation
Validate before calling
if (parentResource is null || parentResource.ConnectionStringResource is null)
throw new InvalidOperationException("Blob container parent must have a connection string resource."); Prevention
- Always create blob containers as children of a properly connected storage resource
- Ensure the storage parent runs before dependent health checks execute
When it happens
Trigger: Calling builder.AddBlobContainer(...) on a resource whose ConnectionStringResource / connection string callback returned null when the health check factory executed.
Common situations: 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.
Understand the failure class
Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.
Related errors
- BlobServiceClient is not initialized.
- Connection string is unavailable
- 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/01213c00004f5547.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs:502
[AspireExport]
public static IResourceBuilder<AzureBlobStorageContainerResource> AddBlobContainer(this IResourceBuilder<AzureStorageResource> builder, [ResourceName] string name, string? blobContainerName = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(name);
blobContainerName ??= name;
var parentBuilder = builder.Resource.ImplicitBlobService ??= GetBlobService(builder);
AzureBlobStorageContainerResource resource = new(name, blobContainerName, parentBuilder.Resource);
builder.Resource.BlobContainers.Add(resource);
string? connectionString = null;
var healthCheckKey = $"{resource.Name}_check";
BlobServiceClient? blobServiceClient = null;
builder.ApplicationBuilder.Services.AddHealthChecks().AddAzureBlobStorage(
sp => blobServiceClient ??= CreateBlobServiceClient(connectionString ?? throw new InvalidOperationException("Connection string is not initialized.")),
optionsFactory: sp => new HealthChecks.Azure.Storage.Blobs.AzureBlobStorageHealthCheckOptions { ContainerName = blobContainerName },
name: healthCheckKey);
return builder.ApplicationBuilder
.AddResource(resource)
.WithIconName("FolderOpen")
.WithHealthCheck(healthCheckKey)
.OnConnectionStringAvailable(async (containerResource, @event, ct) =>
{
connectionString = await resource.Parent.ConnectionStringExpression.GetValueAsync(ct).ConfigureAwait(false);
});
}
/// <summary>
/// Creates a builder for the <see cref="AzureDataLakeStorageFileSystemResource"/> which can be referenced to get the Azure DataLake file system connection string.
/// </summary>
/// <ats-summary>Adds an Azure Data Lake Storage file system resource</ats-summary>
/// <param name="builder">The <see cref="IResourceBuilder{T}"/> for <see cref="AzureStorageResource"/>.</param>View on GitHub (pinned to 25830f84bd)