microsoft/aspire · error · InvalidOperationException

A BlobServiceClient could not be configured. Ensure valid…

Error message

A BlobServiceClient could not be configured. Ensure valid connection information was provided in 'ConnectionStrings:{connectionName}' or specify a 'ConnectionString' or 'ServiceUri' in the '{configurationSectionName}' configuration section.

What it means

Same family as the BlobServiceClient error: after validating the container name, the BlobContainerComponent requires either ConnectionString or ServiceUri to build the underlying BlobServiceClient used to create the BlobContainerClient. Thrown when both are absent.

Solutions

  1. Add "ConnectionStrings": { "<connectionName>": "<storage connection string>" }
  2. Set "ServiceUri": "https://<account>.blob.core.windows.net/" in the Aspire:Azure:Storage:Blobs section
  3. Add .WithReference(storage) in the AppHost wiring so connection info is injected
  4. Verify the connectionName argument matches the ConnectionStrings key

Example fix

// before
"Aspire:Azure:Storage:Blobs": { "ContainerName": "mycontainer" } // no connection info
// after
"Aspire:Azure:Storage:Blobs": { "ContainerName": "mycontainer", "ServiceUri": "https://acct.blob.core.windows.net/" }
Defensive patterns

Strategy: validation

Validate before calling

if (builder.Configuration.GetConnectionString(connectionName) is null &&
    builder.Configuration["Aspire:Azure:Storage:Blobs:ServiceUri"] is null)
    throw new InvalidOperationException("Provide connection info before adding the blob container client.");

Prevention

When it happens

Trigger: Calling AddAzureBlobContainerClient with BlobContainerName set but no 'ConnectionStrings:<connectionName>' and no ConnectionString/ServiceUri in the 'Aspire:Azure:Storage:Blobs' section.

Common situations: Container name configured but connection info forgotten; WithReference missing in AppHost so no connection string injected; connection string key renamed.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/0a539b9a22ddf520. Report an issue: GitHub.

Appendix: source

Thrown at src/Components/Aspire.Azure.Storage.Blobs/AspireBlobStorageExtensions.BlobStorageContainerComponent.cs:35

partial class AspireBlobStorageExtensions
{
    private sealed partial class BlobStorageContainerComponent : AzureComponent<AzureBlobStorageContainerSettings, BlobContainerClient, BlobClientOptions>
    {
        protected override IAzureClientBuilder<BlobContainerClient, BlobClientOptions> AddClient(
            AzureClientFactoryBuilder azureFactoryBuilder, AzureBlobStorageContainerSettings settings, string connectionName, string configurationSectionName)
        {
            return ((IAzureClientFactoryBuilderWithCredential)azureFactoryBuilder).RegisterClientFactory<BlobContainerClient, BlobClientOptions>((options, cred) =>
            {
                if (string.IsNullOrEmpty(settings.BlobContainerName))
                {
                    throw new InvalidOperationException($"The connection string '{connectionName}' does not exist or is missing the container name.");
                }

                var connectionString = settings.ConnectionString;
                if (string.IsNullOrEmpty(connectionString) && settings.ServiceUri is null)
                {
                    throw new InvalidOperationException($"A BlobServiceClient could not be configured. Ensure valid connection information was provided in 'ConnectionStrings:{connectionName}' or specify a 'ConnectionString' or 'ServiceUri' in the '{configurationSectionName}' configuration section.");
                }

                var blobServiceClient = !string.IsNullOrEmpty(connectionString) ? new BlobServiceClient(connectionString, options) :
                    cred is not null ? new BlobServiceClient(settings.ServiceUri, cred, options) :
                    new BlobServiceClient(settings.ServiceUri, options);

                var containerClient = blobServiceClient.GetBlobContainerClient(settings.BlobContainerName);
                return containerClient;
            }, requiresCredential: false);
        }

        protected override void BindClientOptionsToConfiguration(IAzureClientBuilder<BlobContainerClient, BlobClientOptions> clientBuilder, IConfiguration configuration)
        {
#pragma warning disable IDE0200 // Remove unnecessary lambda expression - needed so the ConfigBinder Source Generator works
            clientBuilder.ConfigureOptions(options => configuration.Bind(options));
#pragma warning restore IDE0200
        }

View on GitHub (pinned to 25830f84bd)