{"record":{"id":"d81286365ee766b6","repo":"microsoft/aspire","slug":"could-not-find-a-storageaccount-resource-in-the","errorCode":null,"errorMessage":"Could not find a StorageAccount resource in the infrastructure. Ensure that the provided storage builder creates a StorageAccount resource.","messagePattern":"Could not find a StorageAccount resource in the infrastructure\\. Ensure that the provided storage builder creates a StorageAccount resource\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sql/AzureSqlExtensions.cs","lineNumber":469,"sourceCode":"        ArgumentNullException.ThrowIfNull(builder);\n        ArgumentNullException.ThrowIfNull(storage);\n\n        if (!builder.ApplicationBuilder.ExecutionContext.IsPublishMode)\n        {\n            return builder;\n        }\n\n        // Set the user's storage. The BeforeStartEvent handler will remove the\n        // original default storage since it no longer matches.\n        builder.Resource.DeploymentScriptStorage = storage.Resource;\n\n        // If the storage is not an existing resource, ensure AllowSharedKeyAccess is enabled\n        if (!storage.Resource.IsExisting())\n        {\n            storage.ConfigureInfrastructure(infra =>\n            {\n                var sa = infra.GetProvisionableResources().OfType<StorageAccount>().SingleOrDefault()\n                    ?? throw new InvalidOperationException(\"Could not find a StorageAccount resource in the infrastructure. Ensure that the provided storage builder creates a StorageAccount resource.\");\n\n                sa.AllowSharedKeyAccess = true;\n            });\n        }\n\n        return builder;\n    }\n}\n","sourceCodeStart":451,"sourceCodeEnd":478,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sql/AzureSqlExtensions.cs#L451-L478","documentation":"WithAdminDeploymentScriptStorage throws InvalidOperationException when the provided storage builder's infrastructure contains no StorageAccount provisionable resource. The method requires exactly one StorageAccount to enable shared key access for deployment script file shares.","triggerScenarios":"Calling WithAdminDeploymentScriptStorage with a storage builder whose ConfigureInfrastructure model lacks a StorageAccount — e.g. the builder creates only queues/tables/blobs without a top-level account, or infrastructure was customized to remove the account.","commonSituations":"Passing a storage builder created from an existing resource with custom infrastructure that replaced or removed the account; passing a builder for a non-storage resource by mistake.","solutions":["Ensure the storage builder passed to WithAdminDeploymentScriptStorage creates a StorageAccount (use AddAzureStorage + its default infrastructure).","Review custom ConfigureInfrastructure callbacks and do not remove or rename the StorageAccount resource.","Verify you are passing the storage builder itself, not another Azure resource builder.","Remove a CustomizeAzureInfrastructure call that replaces GetProvisionableResources entries wholesale."],"exampleFix":"// before\nvar storage = builder.AddAzureStorage(\"store\");\nstorage.ConfigureInfrastructure(infra =>\n{\n    infra.Clear(); // removes the StorageAccount\n});\nsql.WithAdminDeploymentScriptStorage(storage); // throws\n\n// after\nvar storage = builder.AddAzureStorage(\"store\");\nsql.WithAdminDeploymentScriptStorage(storage); // StorageAccount present by default","handlingStrategy":"validation","validationCode":"var hasAccount = infra != null && storage.Resource is not null; // plus confirm ConfigureInfrastructure does not remove the StorageAccount","typeGuard":"if (storage.Resource is not null && !storage.Resource.IsExisting()) { /* safe to call WithAdminDeploymentScriptStorage */ }","tryCatchPattern":"try { sql.WithAdminDeploymentScriptStorage(storage); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"StorageAccount\")) { /* inspect ConfigureInfrastructure customizations */ }","preventionTips":["Do not remove or replace provisionable resources in ConfigureInfrastructure.","Pass a plain AddAzureStorage builder to the method.","Confirm the builder targets a storage account, not another Azure resource."],"tags":["azure-sql","storage","infrastructure","resource-missing"],"backgroundTag":"resource-not-found","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"}