{"record":{"id":"54be10d8c45602b8","repo":"microsoft/aspire","slug":"resource-resource-name-has-multiple-container-registries","errorCode":null,"errorMessage":"Resource '{resource.Name}' has multiple container registries available - '{registryNames}'. Please specify which registry to use with '.WithContainerRegistry(registryBuilder)'.","messagePattern":"Resource '(.+?)' has multiple container registries available - '(.+?)'\\. Please specify which registry to use with '\\.WithContainerRegistry\\(registryBuilder\\)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs","lineNumber":1386,"sourceCode":"\n        // Try to get the container registry from DeploymentTargetAnnotation first\n        var deploymentTarget = resource.GetDeploymentTargetAnnotation();\n        if (deploymentTarget?.ContainerRegistry is not null)\n        {\n            return deploymentTarget.ContainerRegistry;\n        }\n\n        // Fall back to RegistryTargetAnnotation (added automatically via BeforeStartEvent)\n        var registryTargetAnnotations = resource.Annotations.OfType<RegistryTargetAnnotation>().ToArray();\n        if (registryTargetAnnotations.Length == 1)\n        {\n            return registryTargetAnnotations[0].Registry;\n        }\n\n        if (registryTargetAnnotations.Length > 1)\n        {\n            var registryNames = string.Join(\", \", registryTargetAnnotations.Select(a => a.Registry is IResource res ? res.Name : a.Registry.ToString()));\n            throw new InvalidOperationException(\n                $\"Resource '{resource.Name}' has multiple container registries available - '{registryNames}'. \" +\n                $\"Please specify which registry to use with '.WithContainerRegistry(registryBuilder)'.\");\n        }\n\n        throw new InvalidOperationException($\"Resource '{resource.Name}' does not have a container registry reference.\");\n    }\n\n    /// <summary>\n    /// Gets the full remote image name for the specified resource, including registry endpoint and tag.\n    /// </summary>\n    /// <param name=\"resource\">The resource to get the remote image name for.</param>\n    /// <param name=\"cancellationToken\">A cancellation token to observe while processing.</param>\n    /// <returns>The fully qualified remote image name.</returns>\n    /// <exception cref=\"InvalidOperationException\">Thrown when the resource does not have a container registry reference.</exception>\n    /// <remarks>\n    /// This method processes any image push options callbacks on the resource and combines the result\n    /// with the container registry to produce the full remote image name.\n    /// </remarks>","sourceCodeStart":1368,"sourceCodeEnd":1404,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L1368-L1404","documentation":"When resolving the container image registry for a resource, more than one ContainerRegistryTarget annotation was found. Aspire cannot infer which registry to publish to, so it requires an explicit choice via .WithContainerRegistry().","triggerScenarios":"Publishing a containerized resource (GetContainerRegistry / GetRemoteImageName path) while the model contains two or more ContainerRegistryTarget annotations from calls like .WithContainerRegistry() with different registry resources.","commonSituations":"Applying .WithContainerRegistry twice with different registries, or having multiple registry resources (e.g., ACR plus a local registry) applied across shared extension helpers on the same resource.","solutions":["Apply .WithContainerRegistry(registryBuilder) with the single desired registry","Remove duplicate .WithContainerRegistry calls so only one registry target remains","Refactor shared extension helpers so only one adds a container registry"],"exampleFix":"// before\nvar acr = builder.AddAzureContainerRegistry(\"acr\");\nresource.WithContainerRegistry(acr);\nresource.WithContainerRegistry(localRegistry); // second registry\n// after\nvar acr = builder.AddAzureContainerRegistry(\"acr\");\nresource.WithContainerRegistry(acr); // exactly one registry","handlingStrategy":"validation","validationCode":"var registries = resource.Annotations.OfType<ContainerRegistryTargetAnnotation>().ToList();\nif (registries.Count > 1) { /* choose one explicitly or throw your own clear error */ }","typeGuard":null,"tryCatchPattern":"try { var registry = resource.GetContainerRegistry(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"multiple container registries\")) { /* apply .WithContainerRegistry and retry */ }","preventionTips":["Apply .WithContainerRegistry exactly once per resource","Audit shared extension helpers for duplicate registry wiring"],"tags":["aspire","containers","publish","ambiguity"],"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"}