{"record":{"id":"d27b0333375b7f09","repo":"microsoft/aspire","slug":"azure-container-app-environments-collisiondetails-multiple","errorCode":null,"errorMessage":"Azure Container App environments {collisionDetails}. Multiple environments with the same managed environment name cannot be deployed to one resource group. {string.Join(\" \", guidance)}","messagePattern":"Azure Container App environments (.+?)\\. Multiple environments with the same managed environment name cannot be deployed to one resource group\\. (.+?)","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs","lineNumber":209,"sourceCode":"                .ToHashSet();\n            var guidance = new List<string>();\n\n            if (namingModes.Contains(ManagedEnvironmentNamingMode.Legacy))\n            {\n                guidance.Add($\"For environments using the default naming convention, call '{nameof(WithUniqueResourceNaming)}()'.\");\n            }\n\n            if (namingModes.Contains(ManagedEnvironmentNamingMode.Unique))\n            {\n                guidance.Add($\"For environments already using '{nameof(WithUniqueResourceNaming)}()', rename one or more resources or configure an explicit name resolver.\");\n            }\n\n            if (namingModes.Contains(ManagedEnvironmentNamingMode.Azd))\n            {\n                guidance.Add($\"For environments using '{nameof(WithAzdResourceNaming)}()', remove it or configure distinct managed environment names explicitly.\");\n            }\n\n            throw new DistributedApplicationException(\n                $\"Azure Container App environments {collisionDetails}. Multiple environments with the same managed environment name cannot be deployed to one resource group. \" +\n                string.Join(\" \", guidance));\n        }\n\n        private static string GetEffectiveNameKey(string expression)\n        {\n            // Normalize the two generated Bicep shapes that use the same 13-character resource-group token:\n            //   take('cae-${uniqueString(resourceGroup().id)}', 60)\n            //   'cae-${resourceToken}'\n            // Evaluating take after substitution catches syntactically different expressions that deploy the\n            // same physical name. Unknown shapes retain their expression as the key.\n            var normalizedExpression = expression\n                .Replace(\"${uniqueString(resourceGroup().id)}\", ResourceGroupTokenPlaceholder, StringComparison.Ordinal)\n                .Replace(\"${resourceToken}\", ResourceGroupTokenPlaceholder, StringComparison.Ordinal);\n\n            const string TakePrefix = \"take('\";\n            const string TakeSeparator = \"', \";\n            if (normalizedExpression.StartsWith(TakePrefix, StringComparison.Ordinal) &&","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs#L191-L227","documentation":"ValidateManagedEnvironmentNames checks that multiple Azure Container App environments do not resolve to the same managed environment name, since Azure cannot deploy multiple managed environments with the same name into one resource group. On collision it throws a DistributedApplicationException with the collision details plus guidance strings (including a hint to remove WithAzdResourceNaming when azd naming mode contributed to the collision).","triggerScenarios":"Declaring two or more AddAzureContainerAppEnvironment resources whose effective managed environment names collide — e.g. both left to azd-generated names via WithAzdResourceNaming(), or both configured with the same explicit name — evaluated during publish infrastructure generation.","commonSituations":"Copying an environment declaration and not renaming it; multiple teams/modules each adding a Container App environment with default naming into one resource group; azd naming mode collapsing distinct environments to identical names.","solutions":["Give each AddAzureContainerAppEnvironment a distinct explicit managed environment name","Remove WithAzdResourceNaming() or ensure azd-named environments resolve to distinct names","Consolidate to a single Container App environment if all container apps should share one environment"],"exampleFix":"// before\nbuilder.AddAzureContainerAppEnvironment(\"envA\").WithAzdResourceNaming();\nbuilder.AddAzureContainerAppEnvironment(\"envB\").WithAzdResourceNaming();\n// after\nbuilder.AddAzureContainerAppEnvironment(\"envA\");\nbuilder.AddAzureContainerAppEnvironment(\"envB\");","handlingStrategy":"validation","validationCode":"var names = builder.Resources.OfType<AzureContainerAppEnvironmentResource>().ToList();\nif (names.GroupBy(e => GetManagedEnvironmentName(e)).Any(g => g.Count() > 1))\n{\n    throw new InvalidOperationException(\"Managed environment names must be unique per resource group\");\n}","typeGuard":null,"tryCatchPattern":"try { await PublishAsync(model); }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"managed environment name\"))\n{\n    logger.LogError(ex, \"Duplicate managed environment names detected\");\n}","preventionTips":["Give each Container App environment a unique explicit name","Avoid unconditionally using WithAzdResourceNaming across multiple environments","Share a single environment when apps belong in one environment"],"tags":["azure","container-apps","naming-collision","publish"],"backgroundTag":"conflicting-config-options","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"}