microsoft/aspire · error · InvalidOperationException
BlobServiceClient is not initialized.
Error message
BlobServiceClient is not initialized.
What it means
RunAsEmulator registers an Azure Blob Storage health check whose factory resolves the captured blobServiceClient. If it is still null when the health check runs, the factory throws this InvalidOperationException, surfacing as a failed health check for the storage resource.
Solutions
- Let the standard RunAsEmulator pipeline run; do not bypass or replace its client registration
- Check that the emulator container starts (image pull, ports) so the connection string resolves and the client is created
- Retry the app host run; if reproducible, upgrade Aspire.Hosting.Azure.Storage
Example fix
// before
.AddAzureBlobStorage(sp => blobServiceClient ?? throw new InvalidOperationException("BlobServiceClient is not initialized."), name: healthCheckKey)
// after: ensure client creation happens eagerly once the connection string is known
.AddAzureBlobStorage(sp => blobServiceClient ??= CreateBlobServiceClient(connectionString!), name: healthCheckKey) Defensive patterns
Strategy: validation
Validate before calling
// Confirm the emulator starts before waiting on health checks
if (!storageResource.Resource.IsEmulator) throw new InvalidOperationException("Expected emulator storage"); Prevention
- Do not replace or wrap RunAsEmulator's internal client registration
- Verify Azurite image pull and port availability so startup completes and initialization runs
- Upgrade packages if initialization-order bugs are suspected
When it happens
Trigger: App host startup with the emulator: the health check `{resource}_check` executes and its `sp => blobServiceClient ?? throw ...` lambda finds the client null because the connection string resolution step never initialized it.
Common situations: Waiting on the storage resource before the connection string callback executes; emulator image configuration errors preventing initialization; running a modified/older version of RunAsEmulator internals.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- is not initialized.
- Emulator currently does not support data lake.
- Cannot create a Microsoft Foundry project connection to an…
- Connection string is not initialized.
- The Azure Storage resource is not running in the local…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/b20a98e19bb9d3e5.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs:250
foreach (var container in builder.Resource.BlobContainers)
{
var blobContainerClient = blobServiceClient.GetBlobContainerClient(container.BlobContainerName);
await blobContainerClient.CreateIfNotExistsAsync(cancellationToken: ct).ConfigureAwait(false);
}
foreach (var queue in builder.Resource.Queues)
{
var queueClient = queueServiceClient.GetQueueClient(queue.QueueName);
await queueClient.CreateIfNotExistsAsync(cancellationToken: ct).ConfigureAwait(false);
}
});
// Add the "Storage" resource health check. There will be separate health checks for the nested child resources.
var healthCheckKey = $"{builder.Resource.Name}_check";
builder.ApplicationBuilder.Services.AddHealthChecks().AddAzureBlobStorage(sp =>
{
return blobServiceClient ?? throw new InvalidOperationException("BlobServiceClient is not initialized.");
}, name: healthCheckKey);
builder.WithHealthCheck(healthCheckKey);
// The default arguments list is coming from https://github.com/Azure/Azurite/blob/c3f93445fbd8fd54d380eb265a5665166c460d2b/Dockerfile#L47C6-L47C106
// They need to be repeated in order to be able to add --skipApiVersionCheck
// --disableProductStyleUrl is required to ensure the emulator uses path-style URLs, and not “product-style” URLs which have the account name in the host name of the URL.
var surrogate = new AzureStorageEmulatorResource(builder.Resource);
var surrogateBuilder = builder.ApplicationBuilder
.CreateResourceBuilder(surrogate)
.WithArgs("azurite", "-l", "/data", "--blobHost", "0.0.0.0", "--queueHost", "0.0.0.0", "--tableHost", "0.0.0.0", "--disableProductStyleUrl", SkipApiVersionCheckArgument);
configureContainer?.Invoke(surrogateBuilder);
return builder;
}
View on GitHub (pinned to 25830f84bd)