microsoft/aspire · error · InvalidOperationException
The container registry configured for the Azure App Service…
Error message
The container registry configured for the Azure App Service 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 App Service Environment may have an explicitly configured container registry via WithAzureContainerRegistry. This getter verifies the configured registry is an AzureContainerRegistryResource; any other registry type is unsupported because App Service requires Azure Container Registry, and the error names the environment and the remedy.
Solutions
- Create a real Azure Container Registry: builder.AddAzureContainerRegistry("acr") and pass that resource to WithAzureContainerRegistry.
- Verify the argument passed to WithAzureContainerRegistry is an IResourceBuilder<AzureContainerRegistryResource>, not another registry type.
- Remove the WithAzureContainerRegistry call to let Aspire attach its default ACR automatically.
- If using existing resources, ensure the referenced registry resource type is AzureContainerRegistryResource.
Example fix
// before
var registry = builder.AddContainerRegistry("my-registry"); // non-ACR type
var env = builder.AddAzureAppServiceEnvironment("env").WithAzureContainerRegistry(registry);
// after
var acr = builder.AddAzureContainerRegistry("acr");
var env = builder.AddAzureAppServiceEnvironment("env").WithAzureContainerRegistry(acr); Defensive patterns
Strategy: validation
Validate before calling
if (registryBuilder?.Resource is not AzureContainerRegistryResource) throw new ArgumentException("WithAzureContainerRegistry requires an Azure Container Registry resource."); Type guard
static bool IsAcr(IResourceBuilder<IResource> b) => b.Resource is AzureContainerRegistryResource;
Try / catch
try { env.WithAzureContainerRegistry(registryBuilder); } catch (InvalidOperationException ex) when (ex.Message.Contains("not an Azure Container Registry")) { logger.LogError(ex, "Use AddAzureContainerRegistry for App Service environments"); } Prevention
- Only pass resources from AddAzureContainerRegistry to WithAzureContainerRegistry.
- Rely on the automatic default ACR when no custom registry is needed.
- Type-check registry builders at the call site when wrapping the API in helpers.
When it happens
Trigger: Calling .WithAzureContainerRegistry(registry) on an App Service environment with a registry resource that is not an AzureContainerRegistryResource (e.g. a generic container registry or third-party registry resource), then publishing — the resource's registry getter throws when resolved.
Common situations: Attaching a generic registry resource used for other targets (Docker Hub, mocks); passing the wrong variable into WithAzureContainerRegistry after a refactor; wiring a registry created by a different integration into the App Service environment.
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
- The Container Registry associated with resource
- The container registry configured for the Azure Cognitive…
- A purge task with the name
- A of type cannot be assigned to a BicepValue< >.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/0253f4a810cc5941.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentResource.cs:493
}
/// <summary>
/// Gets the Azure Container Registry resource used by this Azure App Service 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 App Service 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;
return ReferenceExpression.Create($"{resource.Name.ToLowerInvariant()}-{WebSiteSuffix}.azurewebsites.net");View on GitHub (pinned to 25830f84bd)