microsoft/aspire · error · InvalidOperationException

The published Rust app

Error message

The published Rust app '{resource.Name}' was not converted to a Dockerfile container resource.

What it means

In publish mode, AddRustApp must transform the RustAppResource into a Dockerfile-based ContainerResource carrying the provisional DockerfileBuildAnnotation. If TryCreateResourceBuilder<ContainerResource> fails or the annotation is missing, the publish pipeline cannot produce the container and this InvalidOperationException is thrown.

Solutions

  1. Check for duplicate resource names in the AppHost (two builders with resource.Name).
  2. Remove or fix custom transformation callbacks that delete or replace the Rust resource before FinalizePublishDockerfile runs.
  3. Create the resource via AddRustApp so the provisional DockerfileBuildAnnotation is added.
  4. Inspect the published model to confirm a ContainerResource with that name exists before publishing.

Example fix

// before
var rust = builder.AddRustApp("api", ...); builder.AddRustApp("api", ...); // duplicate name breaks lookup
// after
var rust = builder.AddRustApp("api", ...);
Defensive patterns

Strategy: validation

Validate before calling

if (builder.Resources.Select(r => r.Name).GroupBy(n => n).Any(g => g.Count() > 1))
    throw new InvalidOperationException("Duplicate resource names prevent Rust publish conversion");

Try / catch

try { appBuilder.Build().Run(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("was not converted to a Dockerfile container resource")) {
    logger.LogError("Check publish transformations and resource name uniqueness");
}

Prevention

When it happens

Trigger: Publishing an app whose model contains a Rust resource that was not converted — e.g. the resource name collides with another resource so builder lookup fails, model transformation was skipped, or a custom IResource transformation removed the DockerfileBuildAnnotation.

Common situations: Custom publish callbacks that rebuild/remove resources; duplicate resource names; calling publish APIs against a resource created outside AddRustApp; interrupted model transformation.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Rust/RustHostingExtensions.cs:153

        // on resource name and therefore finds the substituted container's build steps.
        resourceBuilder.WithPipelineConfiguration(context =>
        {
            if (resource.TryGetAnnotationsOfType<ContainerFilesDestinationAnnotation>(out var containerFilesAnnotations))
            {
                var buildSteps = context.GetSteps(resource, WellKnownPipelineTags.BuildCompute);
                foreach (var containerFile in containerFilesAnnotations)
                {
                    buildSteps.DependsOn(context.GetSteps(containerFile.Source, WellKnownPipelineTags.BuildCompute));
                }
            }
        });

        if (builder.ExecutionContext.IsPublishMode)
        {
            if (!builder.TryCreateResourceBuilder<ContainerResource>(resource.Name, out var containerBuilder)
                || !containerBuilder.Resource.TryGetLastAnnotation<DockerfileBuildAnnotation>(out var provisionalDockerfile))
            {
                throw new InvalidOperationException(
                    $"The published Rust app '{resource.Name}' was not converted to a Dockerfile container resource.");
            }

            var publishState = new RustPublishState();
            containerBuilder.WithContainerBuildOptions(context =>
            {
                if (publishState.TargetPlatform is { } targetPlatform)
                {
                    context.TargetPlatform = targetPlatform;
                }
            });

            builder.OnBeforeStart((_, _) =>
            {
                FinalizePublishDockerfile(builder, resource, provisionalDockerfile, publishState);
                return Task.CompletedTask;
            });
        }

View on GitHub (pinned to 25830f84bd)