{"record":{"id":"479924c053b7fb8b","repo":"microsoft/aspire","slug":"no-container-registry-associated-with-environment","errorCode":null,"errorMessage":"No container registry associated with environment '{appEnvResource.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.AppContainers/AzureContainerAppExtensions.cs","lineNumber":349,"sourceCode":"\n                infra.Add(newIdentity);\n                managedIdentityIdOutputValue = newIdentity.Id.ToBicepExpression();\n            }\n\n            AzureProvisioningResource? registry = null;\n            if (appEnvResource.TryGetLastAnnotation<ContainerRegistryReferenceAnnotation>(out var registryReferenceAnnotation) &&\n                registryReferenceAnnotation.Registry is AzureProvisioningResource explicitRegistry)\n            {\n                registry = explicitRegistry;\n            }\n            else if (appEnvResource.DefaultContainerRegistry is not null)\n            {\n                registry = appEnvResource.DefaultContainerRegistry;\n            }\n\n            if (registry is null)\n            {\n                throw new InvalidOperationException($\"No container registry associated with environment '{appEnvResource.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            OperationalInsightsWorkspace? laWorkspace = null;\n            if (appEnvResource.TryGetLastAnnotation<AzureLogAnalyticsWorkspaceReferenceAnnotation>(out var logAnalyticsReferenceAnnotation) && logAnalyticsReferenceAnnotation.Workspace is AzureProvisioningResource workspace)\n            {\n                laWorkspace = (OperationalInsightsWorkspace)workspace.AddAsExistingResource(infra);","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs#L331-L367","documentation":"When building the infrastructure module for a newly added Azure Container App Environment, the code resolves the environment's associated container registry — which the framework is supposed to attach automatically (as DefaultContainerRegistry or via the registry accessor). If no registry is present, this InvalidOperationException is thrown because it indicates the automatic wiring never happened.","triggerScenarios":"Publishing a model where an AzureContainerAppEnvironmentResource reaches registry wiring (AddAzureContainerAppEnvironment publish path) with both the environment-provided registry and DefaultContainerRegistry null — i.e. the framework's automatic registry initialization was skipped or failed.","commonSituations":"Version skew between Aspire.Hosting.Azure.AppContainers packages, custom model transformations that strip environment annotations/resources before publish, or partial initialization when constructing the environment resource programmatically in tests.","solutions":["Align all Aspire.Hosting.Azure.* package versions and rebuild","Remove custom model transformations that remove or alter the Container App environment's registry annotations","Ensure the environment is created via builder.AddAzureContainerAppEnvironment (not manually constructed) so auto-wiring runs","If it persists, file an Aspire issue with your AppHost and publish output"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (appEnvResource.DefaultContainerRegistry is null)\n{\n    throw new InvalidOperationException($\"Environment '{appEnvResource.Name}' lacks its auto-added registry; check package versions\");\n}","typeGuard":null,"tryCatchPattern":"try { await PublishAsync(model); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No container registry associated\"))\n{\n    logger.LogError(ex, \"Automatic registry wiring missing for Container App environment\");\n}","preventionTips":["Create environments only via builder.AddAzureContainerAppEnvironment","Avoid custom model transformations that strip registry wiring","Keep Aspire.Hosting.Azure.* versions aligned"],"tags":["azure","container-apps","container-registry","publish","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}