microsoft/aspire · error · InvalidOperationException

Could not find a StorageAccount resource in the…

Error message

Could not find a StorageAccount resource in the infrastructure.

What it means

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.

Solutions

  1. Check custom ConfigureInfrastructure/event handlers for code that removes or renames the StorageAccount in the storage module.
  2. Align all Aspire.Hosting.Azure.* package versions so storage defaults are consistent.
  3. Remove conflicting private-endpoint customizations around the SQL server and rely on built-in behavior.
  4. If persistent, inspect the storage module's GetProvisionableResources in a debug hook to see what was actually created.

Example fix

// before
storageBuilder.ConfigureInfrastructure(infra =>
{
    // custom code removed non-storage resources including the StorageAccount
    infra.GetProvisionableResources()
         .Where(r => r is not StorageQueue)
         .ToList()
         .ForEach(r => infra.Remove(r));
});

// after
storageBuilder.ConfigureInfrastructure(infra =>
{
    // only touch what you own; leave the StorageAccount intact
    foreach (var queue in infra.GetProvisionableResources().OfType<StorageQueue>()) { /* adjust */ }
});
Defensive patterns

Strategy: try-catch

Validate before calling

// No public pre-check; guard with custom infrastructure handlers that never remove the StorageAccount.

Try / catch

try { sqlBuilder.AddPrivateEndpoint(...); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Could not find a StorageAccount")) { /* check eventing/ConfigureInfrastructure that mutated the storage module */ }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Azure.Sql/AzureSqlServerResource.cs:628

        public IEnumerable<string> GetPrivateDnsZoneNames() => ["privatelink.file.core.windows.net"];

        public IEnumerable<string> GetPrivateLinkGroupIds()
        {
            yield return "file";
        }
    }

    private static IResourceBuilder<AzureStorageResource> CreateDeploymentScriptStorage(IDistributedApplicationBuilder builder, IResourceBuilder<AzureSqlServerResource> azureSqlServer)
    {
        var sqlName = azureSqlServer.Resource.Name;
        var storageName = $"{sqlName.Substring(0, Math.Min(sqlName.Length, 10))}-store";

        return builder.AddAzureStorage(storageName)
            .ConfigureInfrastructure(infra =>
            {
                var sa = infra.GetProvisionableResources().OfType<StorageAccount>().SingleOrDefault()
                    ?? throw new InvalidOperationException("Could not find a StorageAccount resource in the infrastructure.");

                // Deployment scripts require shared key access for file share mounting.
                sa.AllowSharedKeyAccess = true;
            });
    }

    private static void PrepareDeploymentScriptInfrastructure(DistributedApplicationModel appModel, AzureSqlServerResource sql, AzureStorageResource? implicitStorage)
    {
        var hasPe = sql.HasAnnotationOfType<PrivateEndpointTargetAnnotation>();
        var hasRoleAssignments = sql.HasAnnotationOfType<DefaultRoleAssignmentsAnnotation>();

        // When there's no private endpoint or no role assignments (e.g. ClearDefaultRoleAssignments was called),
        // remove all deployment script infrastructure since the deployment scripts won't run.
        if (!hasPe || !hasRoleAssignments)
        {
            if (implicitStorage is not null)
            {
                sql.RemoveDeploymentScriptStorage(appModel, implicitStorage);

View on GitHub (pinned to 25830f84bd)