microsoft/aspire · error · DistributedApplicationException

Could not get the container image name for resource

Error message

Could not get the container image name for resource '{container.Name}'.

What it means

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.

Solutions

  1. Pass an explicit image (e.g. builder.AddContainer("redis", "redis:7")) so the image name resolves.
  2. If creating ContainerResource manually, annotate it with ContainerImageAnnotation specifying Image, Registry and Tag.
  3. Verify any ContainerImageAnnotationCallback sets the annotation before publish.

Example fix

// before
var c = new ContainerResource("cache");
builder.AddResource(c);
// after
builder.AddContainer("cache", "redis", "7.4");
Defensive patterns

Strategy: validation

Validate before calling

if (!container.TryGetContainerImageName(out var image))
{
    throw new InvalidOperationException($"Container '{container.Name}' has no image name; pass one to AddContainer or annotate ContainerImageAnnotation.");
}

Type guard

static bool HasImageName(ContainerResource c) => c.TryGetContainerImageName(out _);

Prevention

When it happens

Trigger: 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.

Common situations: Manually building ContainerResource in extensions or tests without setting the image annotation; misconfigured custom container helpers; refactors that drop the image name argument.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/f0f06075fad3cd53. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs:329

    /// Writes JSON elements to the manifest which represent a container resource.
    /// </summary>
    /// <param name="container">The container resource to written to the manifest.</param>
    /// <exception cref="DistributedApplicationException">Thrown if the container resource does not contain a <see cref="ContainerImageAnnotation"/>.</exception>
    public async Task WriteContainerAsync(ContainerResource container)
    {
        var deploymentTarget = container.GetDeploymentTargetAnnotation();

        if (container.Annotations.OfType<DockerfileBuildAnnotation>().Any())
        {
            Writer.WriteString("type", "container.v1");
            WriteConnectionString(container);
            await WriteBuildContextAsync(container).ConfigureAwait(false);
        }
        else
        {
            if (!container.TryGetContainerImageName(out var image))
            {
                throw new DistributedApplicationException($"Could not get the container image name for resource '{container.Name}'.");
            }

            if (deploymentTarget is not null)
            {
                Writer.WriteString("type", "container.v1");
            }
            else
            {
                Writer.WriteString("type", "container.v0");
            }

            WriteConnectionString(container);
            Writer.WriteString("image", image);
        }

        if (deploymentTarget is not null)
        {
            await WriteDeploymentTarget(deploymentTarget).ConfigureAwait(false);

View on GitHub (pinned to 25830f84bd)