{"record":{"id":"b20a98e19bb9d3e5","repo":"microsoft/aspire","slug":"blobserviceclient-is-not-initialized","errorCode":null,"errorMessage":"BlobServiceClient is not initialized.","messagePattern":"BlobServiceClient is not initialized\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs","lineNumber":250,"sourceCode":"                foreach (var container in builder.Resource.BlobContainers)\n                {\n                    var blobContainerClient = blobServiceClient.GetBlobContainerClient(container.BlobContainerName);\n                    await blobContainerClient.CreateIfNotExistsAsync(cancellationToken: ct).ConfigureAwait(false);\n                }\n\n                foreach (var queue in builder.Resource.Queues)\n                {\n                    var queueClient = queueServiceClient.GetQueueClient(queue.QueueName);\n                    await queueClient.CreateIfNotExistsAsync(cancellationToken: ct).ConfigureAwait(false);\n                }\n            });\n\n        // Add the \"Storage\" resource health check. There will be separate health checks for the nested child resources.\n        var healthCheckKey = $\"{builder.Resource.Name}_check\";\n\n        builder.ApplicationBuilder.Services.AddHealthChecks().AddAzureBlobStorage(sp =>\n        {\n            return blobServiceClient ?? throw new InvalidOperationException(\"BlobServiceClient is not initialized.\");\n        }, name: healthCheckKey);\n\n        builder.WithHealthCheck(healthCheckKey);\n\n        // The default arguments list is coming from https://github.com/Azure/Azurite/blob/c3f93445fbd8fd54d380eb265a5665166c460d2b/Dockerfile#L47C6-L47C106\n        // They need to be repeated in order to be able to add --skipApiVersionCheck\n        // --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.\n\n        var surrogate = new AzureStorageEmulatorResource(builder.Resource);\n        var surrogateBuilder = builder.ApplicationBuilder\n            .CreateResourceBuilder(surrogate)\n            .WithArgs(\"azurite\", \"-l\", \"/data\", \"--blobHost\", \"0.0.0.0\", \"--queueHost\", \"0.0.0.0\", \"--tableHost\", \"0.0.0.0\", \"--disableProductStyleUrl\", SkipApiVersionCheckArgument);\n\n        configureContainer?.Invoke(surrogateBuilder);\n\n        return builder;\n    }\n","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Storage/AzureStorageExtensions.cs#L232-L268","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n.AddAzureBlobStorage(sp => blobServiceClient ?? throw new InvalidOperationException(\"BlobServiceClient is not initialized.\"), name: healthCheckKey)\n// after: ensure client creation happens eagerly once the connection string is known\n.AddAzureBlobStorage(sp => blobServiceClient ??= CreateBlobServiceClient(connectionString!), name: healthCheckKey)","handlingStrategy":"validation","validationCode":"// Confirm the emulator starts before waiting on health checks\nif (!storageResource.Resource.IsEmulator) throw new InvalidOperationException(\"Expected emulator storage\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["azure-storage","emulator","health-check","azurite","initialization-order"],"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"}