microsoft/aspire · error · InvalidOperationException
No container registry associated with environment
Error message
No container registry associated with environment '{resource.Name}'. This should have been added automatically. What it means
When configuring the App Service environment infrastructure, the environment must have a container registry for app images. Aspire normally attaches a default Azure Container Registry automatically; if the resolved registry (configured or default) is still null, the environment is in an internally inconsistent state and the extension throws.
Solutions
- Explicitly attach a registry: call .WithAzureContainerRegistry(...) on the environment resource.
- Ensure automatic registry creation isn't disabled (check AzureProvisioningOptions / related flags).
- Verify the environment resource is the standard AzureAppServiceEnvironmentResource (custom subclasses may not populate DefaultContainerRegistry).
- Update Aspire.Hosting.Azure.AppService packages so automatic registry provisioning works, then re-publish.
Example fix
// before
var env = builder.AddAzureAppServiceEnvironment("env");
// after
var acr = builder.AddAzureContainerRegistry("acr");
var env = builder.AddAzureAppServiceEnvironment("env").WithAzureContainerRegistry(acr); Defensive patterns
Strategy: validation
Validate before calling
var env = builder.AddAzureAppServiceEnvironment("env"); if (env.Resource.DefaultContainerRegistry is null && !explicitRegistryConfigured) { /* attach one explicitly */ } Try / catch
try { env = builder.AddAzureAppServiceEnvironment("env"); } catch (InvalidOperationException ex) when (ex.Message.Contains("container registry")) { logger.LogError(ex, "Attach an ACR via WithAzureContainerRegistry"); } Prevention
- Explicitly call WithAzureContainerRegistry rather than relying on auto-creation in constrained environments.
- Keep Aspire.Hosting.Azure.* packages on consistent versions.
- Don't override environment infrastructure in ways that drop registry attachment.
When it happens
Trigger: Calling AddAzureAppServiceEnvironment where WithAzureContainerRegistry was not used AND resource.DefaultContainerRegistry resolved to null — e.g. the auto-creation of the default registry was skipped by options/flags, or a custom registry configuration failed to attach.
Common situations: Publishing with configurations that suppress automatic Azure Container Registry creation; overriding default infra in a way that drops the registry attachment; package version mismatches in the auto-registry wiring; custom environment subclasses that don't set DefaultContainerRegistry.
Understand the failure class
Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.
Related errors
- The container registry configured for the Azure App Service…
- A purge task with the name
- Ago must be at least 1 minute to be compatible with acr…
- App Service configuration validation failed. See errors…
- App Service context not found for resource
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/b469f0f6b2933c66.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentExtensions.cs:148
infra.Add(newIdentity);
managedIdentityIdOutputValue = newIdentity.Id.ToBicepExpression();
managedIdentityClientIdOutputValue = newIdentity.ClientId.ToBicepExpression();
}
AzureProvisioningResource? registry = null;
if (resource.TryGetLastAnnotation<ContainerRegistryReferenceAnnotation>(out var registryReferenceAnnotation) &&
registryReferenceAnnotation.Registry is AzureProvisioningResource explicitRegistry)
{
registry = explicitRegistry;
}
else if (resource.DefaultContainerRegistry is not null)
{
registry = resource.DefaultContainerRegistry;
}
if (registry is null)
{
throw new InvalidOperationException($"No container registry associated with environment '{resource.Name}'. This should have been added automatically.");
}
var containerRegistry = (ContainerRegistryService)registry.AddAsExistingResource(infra);
infra.Add(containerRegistry);
if (newIdentity is not null)
{
var pullRa = containerRegistry.CreateRoleAssignment(ContainerRegistryBuiltInRole.AcrPull, newIdentity);
// There's a bug in the CDK, see https://github.com/Azure/azure-sdk-for-net/issues/47265
pullRa.Name = BicepFunction.CreateGuid(containerRegistry.Id, newIdentity.Id, pullRa.RoleDefinitionId);
infra.Add(pullRa);
}
AppServicePlan plan;
if (resource.IsExisting())
{
// The Aspire resource models the App Service Plan. When users mark it existing,View on GitHub (pinned to 25830f84bd)