{"record":{"id":"f0f06075fad3cd53","repo":"microsoft/aspire","slug":"could-not-get-the-container-image-name-for-resource","errorCode":null,"errorMessage":"Could not get the container image name for resource '{container.Name}'.","messagePattern":"Could not get the container image name for resource '(.+?)'\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs","lineNumber":329,"sourceCode":"    /// Writes JSON elements to the manifest which represent a container resource.\n    /// </summary>\n    /// <param name=\"container\">The container resource to written to the manifest.</param>\n    /// <exception cref=\"DistributedApplicationException\">Thrown if the container resource does not contain a <see cref=\"ContainerImageAnnotation\"/>.</exception>\n    public async Task WriteContainerAsync(ContainerResource container)\n    {\n        var deploymentTarget = container.GetDeploymentTargetAnnotation();\n\n        if (container.Annotations.OfType<DockerfileBuildAnnotation>().Any())\n        {\n            Writer.WriteString(\"type\", \"container.v1\");\n            WriteConnectionString(container);\n            await WriteBuildContextAsync(container).ConfigureAwait(false);\n        }\n        else\n        {\n            if (!container.TryGetContainerImageName(out var image))\n            {\n                throw new DistributedApplicationException($\"Could not get the container image name for resource '{container.Name}'.\");\n            }\n\n            if (deploymentTarget is not null)\n            {\n                Writer.WriteString(\"type\", \"container.v1\");\n            }\n            else\n            {\n                Writer.WriteString(\"type\", \"container.v0\");\n            }\n\n            WriteConnectionString(container);\n            Writer.WriteString(\"image\", image);\n        }\n\n        if (deploymentTarget is not null)\n        {\n            await WriteDeploymentTarget(deploymentTarget).ConfigureAwait(false);","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L311-L347","documentation":"When writing a container resource to the manifest, if the container was not built from a Dockerfile and has no resolvable container image name annotation, Aspire cannot determine the 'image' property for the manifest and throws. Container image names come from AddContainer's image argument or a ContainerImageAnnotation.","triggerScenarios":"Publishing (manifest or pipeline) a container created with AddResource(new ContainerResource(...)) without specifying an image name; a custom container resource lacking ContainerImageAnnotation; an image callback that leaves the annotation unset.","commonSituations":"Manually building ContainerResource in extensions or tests without setting the image annotation; misconfigured custom container helpers; refactors that drop the image name argument.","solutions":["Pass an explicit image (e.g. builder.AddContainer(\"redis\", \"redis:7\")) so the image name resolves.","If creating ContainerResource manually, annotate it with ContainerImageAnnotation specifying Image, Registry and Tag.","Verify any ContainerImageAnnotationCallback sets the annotation before publish."],"exampleFix":"// before\nvar c = new ContainerResource(\"cache\");\nbuilder.AddResource(c);\n// after\nbuilder.AddContainer(\"cache\", \"redis\", \"7.4\");","handlingStrategy":"validation","validationCode":"if (!container.TryGetContainerImageName(out var image))\n{\n    throw new InvalidOperationException($\"Container '{container.Name}' has no image name; pass one to AddContainer or annotate ContainerImageAnnotation.\");\n}","typeGuard":"static bool HasImageName(ContainerResource c) => c.TryGetContainerImageName(out _);","tryCatchPattern":null,"preventionTips":["Always supply an image name to AddContainer.","Set ContainerImageAnnotation on manually built container resources.","Test manifest generation in CI to catch missing annotations early."],"tags":["manifest","containers","publishing"],"backgroundTag":"resource-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}