{"record":{"id":"0253f4a810cc5941","repo":"microsoft/aspire","slug":"the-container-registry-configured-for-the-azure-app-service","errorCode":null,"errorMessage":"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.","messagePattern":"The container registry configured for the Azure App Service Environment '(.+?)' is not an Azure Container Registry\\. Only Azure Container Registry resources are supported\\. Use '\\.WithAzureContainerRegistry\\(\\)' to configure an Azure Container Registry\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentResource.cs","lineNumber":493,"sourceCode":"    }\n\n    /// <summary>\n    /// Gets the Azure Container Registry resource used by this Azure App Service Environment resource.\n    /// </summary>\n    public AzureContainerRegistryResource? ContainerRegistry\n    {\n        get\n        {\n            var registry = GetContainerRegistry();\n\n            if (registry is null)\n            {\n                return null;\n            }\n\n            if (registry is not AzureContainerRegistryResource azureRegistry)\n            {\n                throw new InvalidOperationException(\n                    $\"The container registry configured for the Azure App Service Environment '{Name}' is not an Azure Container Registry. \" +\n                    $\"Only Azure Container Registry resources are supported. Use '.WithAzureContainerRegistry()' to configure an Azure Container Registry.\");\n            }\n\n            return azureRegistry;\n        }\n    }\n\n#pragma warning disable CS0618 // Type or member is obsolete\n    ReferenceExpression IAzureContainerRegistry.ManagedIdentityId => ReferenceExpression.Create($\"{ContainerRegistryManagedIdentityId}\");\n#pragma warning restore CS0618 // Type or member is obsolete\n\n    /// <inheritdoc/>\n    [Experimental(\"ASPIRECOMPUTE002\", UrlFormat = \"https://aka.ms/aspire/diagnostics/{0}\")]\n    public ReferenceExpression GetHostAddressExpression(EndpointReference endpointReference)\n    {\n        var resource = endpointReference.Resource;\n        return ReferenceExpression.Create($\"{resource.Name.ToLowerInvariant()}-{WebSiteSuffix}.azurewebsites.net\");","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentResource.cs#L475-L511","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar registry = builder.AddContainerRegistry(\"my-registry\"); // non-ACR type\nvar env = builder.AddAzureAppServiceEnvironment(\"env\").WithAzureContainerRegistry(registry);\n// after\nvar acr = builder.AddAzureContainerRegistry(\"acr\");\nvar env = builder.AddAzureAppServiceEnvironment(\"env\").WithAzureContainerRegistry(acr);","handlingStrategy":"validation","validationCode":"if (registryBuilder?.Resource is not AzureContainerRegistryResource) throw new ArgumentException(\"WithAzureContainerRegistry requires an Azure Container Registry resource.\");","typeGuard":"static bool IsAcr(IResourceBuilder<IResource> b) => b.Resource is AzureContainerRegistryResource;","tryCatchPattern":"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\"); }","preventionTips":["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."],"tags":["azure","appservice","container-registry","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}