microsoft/aspire · error · InvalidOperationException
The published Rust app
Error message
The published Rust app '{resource.Name}' was not converted to a container resource. What it means
FinalizePublishDockerfile re-creates a builder for the container resource created during publish. If TryCreateResourceBuilder<ContainerResource> cannot find or create the builder for resource.Name, the later annotation checks cannot proceed and this InvalidOperationException is thrown.
Solutions
- Audit AppHost custom transformations for anything removing/renaming the Rust container resource.
- Ensure resource names are unique across the AppHost.
- Recreate the resource with AddRustApp so the full publish pipeline (conversion + finalization) runs.
- If the transformation order looks correct, minimize to a repro and report with Aspire version.
Defensive patterns
Strategy: validation
Validate before calling
var containerExists = applicationBuilder.Resources.OfType<ContainerResource>().Any(r => r.Name == resource.Name);
if (!containerExists) throw new InvalidOperationException("Rust container resource missing before publish finalization"); Try / catch
try { PublishAsync(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("was not converted to a container resource")) {
logger.LogError("Model transformation lost the Rust container resource; audit transformations");
} Prevention
- Audit custom IResourceTransformation callbacks
- Avoid renaming resources between creation and publish
- Use AddRustApp end-to-end rather than hand-building the resource
When it happens
Trigger: During publish mode finalization of a Rust app: the container resource with the Rust resource's name is absent from applicationBuilder.Resources — typically because model transformation to ContainerResource never happened or the resource was removed/renamed by custom callbacks.
Common situations: Custom IResourceTransformation removing or renaming resources; duplicate names breaking the builder lookup; calling publish APIs on resources not created by AddRustApp; library bug after upgrading Aspire versions.
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
- The published Rust app
- The Rust app ' ' targets ' ', which requires container…
- The Rust app ' ' targets ' ', which cannot be mapped to a…
- The Rust app ' ' targets ' ', which is not compatible with…
- The Rust app ' ' builds from ' ', but its symbolic links…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/5a41237b45bb2291.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Rust/RustHostingExtensions.cs:728
// https://github.com/microsoft/aspire/issues/18956.
// See https://doc.rust-lang.org/cargo/reference/config.html#buildtarget
if (target.Target is null && environment.TryGetValue("CARGO_BUILD_TARGET", out var buildTarget) && buildTarget.Length > 0)
{
target = target with { Target = buildTarget };
}
return target.GetExecutablePath(metadata.TargetDirectory);
}
private static void FinalizePublishDockerfile(
IDistributedApplicationBuilder applicationBuilder,
RustAppResource resource,
DockerfileBuildAnnotation provisionalDockerfile,
RustPublishState publishState)
{
if (!applicationBuilder.TryCreateResourceBuilder<ContainerResource>(resource.Name, out var containerBuilder))
{
throw new InvalidOperationException(
$"The published Rust app '{resource.Name}' was not converted to a container resource.");
}
var annotations = containerBuilder.Resource.Annotations;
if (!containerBuilder.Resource.TryGetLastAnnotation<DockerfileBuildAnnotation>(out var activeDockerfile)
|| !ReferenceEquals(activeDockerfile, provisionalDockerfile))
{
// PublishAsDockerFile is idempotent, so callers can replace the integration's provisional
// Dockerfile or factory after AddRustApp returns. That later configuration owns its context,
// generated content, platform, and target handling.
return;
}
ContainerTargetPlatform? targetPlatform = null;
annotations.Remove(provisionalDockerfile);
var workingDirectory = Path.GetFullPath(resource.WorkingDirectory);View on GitHub (pinned to 25830f84bd)