{"record":{"id":"f7415e73061fbd70","repo":"microsoft/aspire","slug":"resource-resource-name-does-not-have-a-container-registry","errorCode":null,"errorMessage":"Resource '{resource.Name}' does not have a container registry reference.","messagePattern":"Resource '(.+?)' does not have a container registry reference\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs","lineNumber":1391,"sourceCode":"            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>\n    [Experimental(\"ASPIREPIPELINES003\", UrlFormat = \"https://aka.ms/aspire/diagnostics#{0}\")]\n    internal static async Task<string> GetFullRemoteImageNameAsync(\n        this IResource resource,\n        CancellationToken cancellationToken)\n    {","sourceCodeStart":1373,"sourceCodeEnd":1409,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs#L1373-L1409","documentation":"The resource has no ContainerRegistryTarget annotation, so there is no registry from which to compose the remote image name. Publishing to a remote registry requires the resource to be associated with a registry.","triggerScenarios":"Calling GetContainerRegistry (directly or via GetRemoteImageName) during publish on a resource that never had .WithContainerRegistry() applied.","commonSituations":"Publishing a container resource without wiring it to an Azure Container Registry or other registry resource; forgetting the registry call in a custom extension method.","solutions":["Call .WithContainerRegistry(registryBuilder) on the resource before publishing","Ensure the registry resource (e.g., AddAzureContainerRegistry) is added to the AppHost and referenced","Check custom extension methods to confirm they propagate the registry annotation"],"exampleFix":"// before\nvar image = resource.GetRemoteImageName();\n// after\nvar acr = builder.AddAzureContainerRegistry(\"myacr\");\nresource.WithContainerRegistry(acr);\nvar image = resource.GetRemoteImageName();","handlingStrategy":"validation","validationCode":"var hasRegistry = resource.Annotations.OfType<ContainerRegistryTargetAnnotation>().Any();\nif (!hasRegistry) { resource.WithContainerRegistry(acr); }","typeGuard":null,"tryCatchPattern":"try { var registry = resource.GetContainerRegistry(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"does not have a container registry\")) { /* wire the registry before publishing */ }","preventionTips":["Always pair container resources with a registry resource in publish scenarios","Centralize registry wiring in one extension method"],"tags":["aspire","containers","publish","missing-annotation"],"backgroundTag":"missing-required-config","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"}