{"record":{"id":"deaa7b9726a97f87","repo":"microsoft/aspire","slug":"could-not-find-a-storageaccount-resource-in-the-deaa7b","errorCode":null,"errorMessage":"Could not find a StorageAccount resource in the infrastructure.","messagePattern":"Could not find a StorageAccount resource in the infrastructure\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Sql/AzureSqlServerResource.cs","lineNumber":628,"sourceCode":"\n        public IEnumerable<string> GetPrivateDnsZoneNames() => [\"privatelink.file.core.windows.net\"];\n\n        public IEnumerable<string> GetPrivateLinkGroupIds()\n        {\n            yield return \"file\";\n        }\n    }\n\n    private static IResourceBuilder<AzureStorageResource> CreateDeploymentScriptStorage(IDistributedApplicationBuilder builder, IResourceBuilder<AzureSqlServerResource> azureSqlServer)\n    {\n        var sqlName = azureSqlServer.Resource.Name;\n        var storageName = $\"{sqlName.Substring(0, Math.Min(sqlName.Length, 10))}-store\";\n\n        return builder.AddAzureStorage(storageName)\n            .ConfigureInfrastructure(infra =>\n            {\n                var sa = infra.GetProvisionableResources().OfType<StorageAccount>().SingleOrDefault()\n                    ?? throw new InvalidOperationException(\"Could not find a StorageAccount resource in the infrastructure.\");\n\n                // Deployment scripts require shared key access for file share mounting.\n                sa.AllowSharedKeyAccess = true;\n            });\n    }\n\n    private static void PrepareDeploymentScriptInfrastructure(DistributedApplicationModel appModel, AzureSqlServerResource sql, AzureStorageResource? implicitStorage)\n    {\n        var hasPe = sql.HasAnnotationOfType<PrivateEndpointTargetAnnotation>();\n        var hasRoleAssignments = sql.HasAnnotationOfType<DefaultRoleAssignmentsAnnotation>();\n\n        // When there's no private endpoint or no role assignments (e.g. ClearDefaultRoleAssignments was called),\n        // remove all deployment script infrastructure since the deployment scripts won't run.\n        if (!hasPe || !hasRoleAssignments)\n        {\n            if (implicitStorage is not null)\n            {\n                sql.RemoveDeploymentScriptStorage(appModel, implicitStorage);","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Sql/AzureSqlServerResource.cs#L610-L646","documentation":"CreateDeploymentScriptStorage throws InvalidOperationException when the freshly added Azure Storage infrastructure does not contain a StorageAccount provisionable resource. This internal helper provisions storage for Azure SQL admin deployment scripts and expects AddAzureStorage to have created exactly one StorageAccount.","triggerScenarios":"Triggered via OnPrivateEndpointCreated when a private endpoint is added to the SQL server and the internal AddAzureStorage call's infrastructure lacks a StorageAccount (e.g. infrastructure filtered/replaced before this callback runs, or a package/extension mismatch altering storage default infrastructure).","commonSituations":"Global infrastructure customization hooks that strip or rename provisionable resources; mixing Aspire package versions where storage defaults differ; custom eventing that interferes with the created storage resource.","solutions":["Check custom ConfigureInfrastructure/event handlers for code that removes or renames the StorageAccount in the storage module.","Align all Aspire.Hosting.Azure.* package versions so storage defaults are consistent.","Remove conflicting private-endpoint customizations around the SQL server and rely on built-in behavior.","If persistent, inspect the storage module's GetProvisionableResources in a debug hook to see what was actually created."],"exampleFix":"// before\nstorageBuilder.ConfigureInfrastructure(infra =>\n{\n    // custom code removed non-storage resources including the StorageAccount\n    infra.GetProvisionableResources()\n         .Where(r => r is not StorageQueue)\n         .ToList()\n         .ForEach(r => infra.Remove(r));\n});\n\n// after\nstorageBuilder.ConfigureInfrastructure(infra =>\n{\n    // only touch what you own; leave the StorageAccount intact\n    foreach (var queue in infra.GetProvisionableResources().OfType<StorageQueue>()) { /* adjust */ }\n});","handlingStrategy":"try-catch","validationCode":"// No public pre-check; guard with custom infrastructure handlers that never remove the StorageAccount.","typeGuard":null,"tryCatchPattern":"try { sqlBuilder.AddPrivateEndpoint(...); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Could not find a StorageAccount\")) { /* check eventing/ConfigureInfrastructure that mutated the storage module */ }","preventionTips":["Keep ConfigureInfrastructure handlers additive; never Clear() provisionable resources.","Pin all Aspire Azure packages to the same version.","Avoid global infrastructure hooks that mutate storage modules created internally.","Test private endpoint flows locally to catch infrastructure mutations early."],"tags":["azure-sql","storage","infrastructure","internal-invariant"],"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"}