{"record":{"id":"5a41237b45bb2291","repo":"microsoft/aspire","slug":"the-published-rust-app-resource-name-was-not-converted-to-a-5a4123","errorCode":null,"errorMessage":"The published Rust app '{resource.Name}' was not converted to a container resource.","messagePattern":"The published Rust app '(.+?)' was not converted to a container resource\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Rust/RustHostingExtensions.cs","lineNumber":728,"sourceCode":"        // https://github.com/microsoft/aspire/issues/18956.\n        // See https://doc.rust-lang.org/cargo/reference/config.html#buildtarget\n        if (target.Target is null && environment.TryGetValue(\"CARGO_BUILD_TARGET\", out var buildTarget) && buildTarget.Length > 0)\n        {\n            target = target with { Target = buildTarget };\n        }\n\n        return target.GetExecutablePath(metadata.TargetDirectory);\n    }\n\n    private static void FinalizePublishDockerfile(\n        IDistributedApplicationBuilder applicationBuilder,\n        RustAppResource resource,\n        DockerfileBuildAnnotation provisionalDockerfile,\n        RustPublishState publishState)\n    {\n        if (!applicationBuilder.TryCreateResourceBuilder<ContainerResource>(resource.Name, out var containerBuilder))\n        {\n            throw new InvalidOperationException(\n                $\"The published Rust app '{resource.Name}' was not converted to a container resource.\");\n        }\n\n        var annotations = containerBuilder.Resource.Annotations;\n        if (!containerBuilder.Resource.TryGetLastAnnotation<DockerfileBuildAnnotation>(out var activeDockerfile)\n            || !ReferenceEquals(activeDockerfile, provisionalDockerfile))\n        {\n            // PublishAsDockerFile is idempotent, so callers can replace the integration's provisional\n            // Dockerfile or factory after AddRustApp returns. That later configuration owns its context,\n            // generated content, platform, and target handling.\n            return;\n        }\n\n        ContainerTargetPlatform? targetPlatform = null;\n\n        annotations.Remove(provisionalDockerfile);\n\n        var workingDirectory = Path.GetFullPath(resource.WorkingDirectory);","sourceCodeStart":710,"sourceCodeEnd":746,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Rust/RustHostingExtensions.cs#L710-L746","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"var containerExists = applicationBuilder.Resources.OfType<ContainerResource>().Any(r => r.Name == resource.Name);\nif (!containerExists) throw new InvalidOperationException(\"Rust container resource missing before publish finalization\");","typeGuard":null,"tryCatchPattern":"try { PublishAsync(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"was not converted to a container resource\")) {\n    logger.LogError(\"Model transformation lost the Rust container resource; audit transformations\");\n}","preventionTips":["Audit custom IResourceTransformation callbacks","Avoid renaming resources between creation and publish","Use AddRustApp end-to-end rather than hand-building the resource"],"tags":["publish","resource-model","rust"],"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-21T04:17:39.646Z"}