microsoft/aspire · error · InvalidOperationException
The container registry configured for the Azure Container…
Error message
The container registry configured for the Azure Container App Environment '{Name}' is not an Azure Container Registry. Only Azure Container Registry resources are supported. Use '.WithAzureContainerRegistry()' to configure an Azure Container Registry. What it means
An Azure Container App Environment requires its configured container registry to be an Aspire AzureContainerRegistryResource. When the environment's registry is some other container registry resource type, this InvalidOperationException is thrown, directing you to configure it via .WithAzureContainerRegistry().
Solutions
- Call .WithAzureContainerRegistry() on the environment to configure a supported AzureContainerRegistryResource
- Remove any custom/foreign registry resource attached to the Container App Environment
- If you must use a non-Azure registry, do not attach it via the Container App Environment registry configuration
Example fix
// before
var env = builder.AddAzureContainerAppEnvironment("env");
env.WithCustomRegistry(nonAzureRegistry);
// after
var env = builder.AddAzureContainerAppEnvironment("env");
env.WithAzureContainerRegistry(); Defensive patterns
Strategy: type-guard
Validate before calling
if (registry is not AzureContainerRegistryResource)
{
throw new InvalidOperationException("Call WithAzureContainerRegistry() to use a supported registry");
} Type guard
static bool IsAzureRegistry(IResource registry) => registry is AzureContainerRegistryResource;
Try / catch
try { await PublishAsync(model); }
catch (InvalidOperationException ex) when (ex.Message.Contains("Azure Container Registry"))
{
logger.LogError(ex, "Environment registry is not an AzureContainerRegistryResource");
} Prevention
- Always configure environment registries via .WithAzureContainerRegistry()
- Do not attach foreign/custom registry resources to Container App Environments
- Validate the registry resource type before publishing
When it happens
Trigger: Publishing a model where the Azure Container App Environment has a registry annotation pointing at a non-Azure registry resource (e.g. a generic/ACR-modelled registry from another integration or a custom IContainerRegistry implementation), during Bicep generation of the environment module.
Common situations: Mixing registry integrations, replacing the default Azure Container Registry with a custom registry resource, or upgrading models where an environment was configured with an incompatible registry type.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- No container registry associated with environment
- Azure Container App environments
- Cannot configure custom domain when resource is not…
- Container app context not found for resource
- Container port is required for all endpoints
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/5a68ddae90e256e0.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppEnvironmentResource.cs:331
}
/// <summary>
/// Gets the Azure Container Registry resource used by this Azure Container App Environment resource.
/// </summary>
public AzureContainerRegistryResource? ContainerRegistry
{
get
{
var registry = GetContainerRegistry();
if (registry is null)
{
return null;
}
if (registry is not AzureContainerRegistryResource azureRegistry)
{
throw new InvalidOperationException(
$"The container registry configured for the Azure Container App Environment '{Name}' is not an Azure Container Registry. " +
$"Only Azure Container Registry resources are supported. Use '.WithAzureContainerRegistry()' to configure an Azure Container Registry.");
}
return azureRegistry;
}
}
#pragma warning disable CS0618 // Type or member is obsolete
ReferenceExpression IAzureContainerRegistry.ManagedIdentityId => ReferenceExpression.Create($"{ContainerRegistryManagedIdentityId}");
#pragma warning restore CS0618 // Type or member is obsolete
/// <inheritdoc/>
[Experimental("ASPIRECOMPUTE002", UrlFormat = "https://aka.ms/aspire/diagnostics/{0}")]
public ReferenceExpression GetHostAddressExpression(EndpointReference endpointReference)
{
var resource = endpointReference.Resource;View on GitHub (pinned to 25830f84bd)