{"record":{"id":"b469f0f6b2933c66","repo":"microsoft/aspire","slug":"no-container-registry-associated-with-environment-resource","errorCode":null,"errorMessage":"No container registry associated with environment '{resource.Name}'. This should have been added automatically.","messagePattern":"No container registry associated with environment '(.+?)'\\. This should have been added automatically\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentExtensions.cs","lineNumber":148,"sourceCode":"                infra.Add(newIdentity);\n                managedIdentityIdOutputValue = newIdentity.Id.ToBicepExpression();\n                managedIdentityClientIdOutputValue = newIdentity.ClientId.ToBicepExpression();\n            }\n\n            AzureProvisioningResource? registry = null;\n            if (resource.TryGetLastAnnotation<ContainerRegistryReferenceAnnotation>(out var registryReferenceAnnotation) &&\n                registryReferenceAnnotation.Registry is AzureProvisioningResource explicitRegistry)\n            {\n                registry = explicitRegistry;\n            }\n            else if (resource.DefaultContainerRegistry is not null)\n            {\n                registry = resource.DefaultContainerRegistry;\n            }\n\n            if (registry is null)\n            {\n                throw new InvalidOperationException($\"No container registry associated with environment '{resource.Name}'. This should have been added automatically.\");\n            }\n\n            var containerRegistry = (ContainerRegistryService)registry.AddAsExistingResource(infra);\n            infra.Add(containerRegistry);\n\n            if (newIdentity is not null)\n            {\n                var pullRa = containerRegistry.CreateRoleAssignment(ContainerRegistryBuiltInRole.AcrPull, newIdentity);\n\n                // There's a bug in the CDK, see https://github.com/Azure/azure-sdk-for-net/issues/47265\n                pullRa.Name = BicepFunction.CreateGuid(containerRegistry.Id, newIdentity.Id, pullRa.RoleDefinitionId);\n                infra.Add(pullRa);\n            }\n\n            AppServicePlan plan;\n            if (resource.IsExisting())\n            {\n                // The Aspire resource models the App Service Plan. When users mark it existing,","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentExtensions.cs#L130-L166","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar env = builder.AddAzureAppServiceEnvironment(\"env\");\n// after\nvar acr = builder.AddAzureContainerRegistry(\"acr\");\nvar env = builder.AddAzureAppServiceEnvironment(\"env\").WithAzureContainerRegistry(acr);","handlingStrategy":"validation","validationCode":"var env = builder.AddAzureAppServiceEnvironment(\"env\"); if (env.Resource.DefaultContainerRegistry is null && !explicitRegistryConfigured) { /* attach one explicitly */ }","typeGuard":null,"tryCatchPattern":"try { env = builder.AddAzureAppServiceEnvironment(\"env\"); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"container registry\")) { logger.LogError(ex, \"Attach an ACR via WithAzureContainerRegistry\"); }","preventionTips":["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."],"tags":["azure","appservice","container-registry"],"backgroundTag":"missing-config-value","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"}