microsoft/aspire · error · InvalidOperationException
Could not find a StorageAccount resource in the…
Error message
Could not find a StorageAccount resource in the infrastructure. Ensure that the provided storage builder creates a StorageAccount resource.
What it means
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.
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.
Example fix
// before
var storage = builder.AddAzureStorage("store");
storage.ConfigureInfrastructure(infra =>
{
infra.Clear(); // removes the StorageAccount
});
sql.WithAdminDeploymentScriptStorage(storage); // throws
// after
var storage = builder.AddAzureStorage("store");
sql.WithAdminDeploymentScriptStorage(storage); // StorageAccount present by default Defensive patterns
Strategy: validation
Validate before calling
var hasAccount = infra != null && storage.Resource is not null; // plus confirm ConfigureInfrastructure does not remove the StorageAccount
Type guard
if (storage.Resource is not null && !storage.Resource.IsExisting()) { /* safe to call WithAdminDeploymentScriptStorage */ } Try / catch
try { sql.WithAdminDeploymentScriptStorage(storage); }
catch (InvalidOperationException ex) when (ex.Message.Contains("StorageAccount")) { /* inspect ConfigureInfrastructure customizations */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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
- Could not find a StorageAccount resource in the…
- Could not determine an appropriate location for local…
- Could not find a with name .
- Emulator currently does not support data lake.
- Emulator currently does not support data lake.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/d81286365ee766b6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Sql/AzureSqlExtensions.cs:469
ArgumentNullException.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(storage);
if (!builder.ApplicationBuilder.ExecutionContext.IsPublishMode)
{
return builder;
}
// Set the user's storage. The BeforeStartEvent handler will remove the
// original default storage since it no longer matches.
builder.Resource.DeploymentScriptStorage = storage.Resource;
// If the storage is not an existing resource, ensure AllowSharedKeyAccess is enabled
if (!storage.Resource.IsExisting())
{
storage.ConfigureInfrastructure(infra =>
{
var sa = infra.GetProvisionableResources().OfType<StorageAccount>().SingleOrDefault()
?? throw new InvalidOperationException("Could not find a StorageAccount resource in the infrastructure. Ensure that the provided storage builder creates a StorageAccount resource.");
sa.AllowSharedKeyAccess = true;
});
}
return builder;
}
}
View on GitHub (pinned to 25830f84bd)