{"record":{"id":"0db1682ba1d5d4b1","repo":"microsoft/aspire","slug":"unable-to-start-cargo-to-inspect-the-rust-app-resourcename","errorCode":null,"errorMessage":"Unable to start 'cargo' to inspect the Rust app '{resourceName}'. Install Rust from https://www.rust-lang.org/tools/install or supply your own Dockerfile in '{workingDirectory}'. {ex.Message}","messagePattern":"Unable to start 'cargo' to inspect the Rust app '(.+?)'\\. Install Rust from https://www\\.rust-lang\\.org/tools/install or supply your own Dockerfile in '(.+?)'\\. (.+?)","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Rust/CargoMetadataReader.cs","lineNumber":92,"sourceCode":"        foreach (var argument in BuildArguments(manifestPath))\n        {\n            startInfo.ArgumentList.Add(argument);\n        }\n\n        foreach (var (name, value) in environment)\n        {\n            startInfo.Environment[name] = value;\n        }\n\n        using var process = new Process { StartInfo = startInfo };\n\n        try\n        {\n            process.Start();\n        }\n        catch (Exception ex)\n        {\n            throw new DistributedApplicationException(\n                $\"Unable to start 'cargo' to inspect the Rust app '{resourceName}'. Install Rust from https://www.rust-lang.org/tools/install \" +\n                $\"or supply your own Dockerfile in '{workingDirectory}'. {ex.Message}\", ex);\n        }\n\n        // Drain both redirected streams concurrently so a full pipe cannot block cargo before it exits.\n        var stdoutTask = process.StandardOutput.ReadToEndAsync(CancellationToken.None);\n        var stderrTask = process.StandardError.ReadToEndAsync(CancellationToken.None);\n\n        using var timeoutSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);\n        timeoutSource.CancelAfter(s_timeout);\n\n        try\n        {\n            await process.WaitForExitAsync(timeoutSource.Token).ConfigureAwait(false);\n        }\n        catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)\n        {\n            TryKillProcess(process);","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Rust/CargoMetadataReader.cs#L74-L110","documentation":"CargoMetadataReader.ReadAsync launches 'cargo metadata' as a child process to inspect the Rust app. If Process.Start itself throws (cargo not installed, not on PATH, or not executable), the reader wraps the exception in DistributedApplicationException with install guidance and the original OS error message.","triggerScenarios":"Aspire.Hosting.Rust resource startup calling ReadAsync when the 'cargo' executable cannot be started: not installed, missing from PATH for the apphost process, or permission/OS-level launch failure.","commonSituations":"Rust not installed on the machine or container; cargo installed only in a user shell profile (e.g. ~/.cargo/env) so the apphost process's PATH lacks it; wrong workingDirectory; running the apphost under a service account without access to the toolchain.","solutions":["Install Rust/cargo from https://www.rust-lang.org/tools/install (rustup) and confirm 'cargo --version' works.","Ensure cargo is on the PATH of the process running the App Host, not just your interactive shell (e.g. add ~/.cargo/bin or CARGO_HOME/bin).","Check the workingDirectory of the Rust resource points at the directory containing Cargo.toml.","Alternatively supply your own Dockerfile for the resource so container builds do not depend on host cargo."],"exampleFix":"// shell — make cargo visible to the apphost process\n// before\n# cargo only on interactive shell PATH via ~/.cargo/env\n\n// after\nexport PATH=\"$HOME/.cargo/bin:$PATH\"  # set for the process launching the App Host / systemd unit / CI job","handlingStrategy":"validation","validationCode":"// Pre-flight check before launching the apphost:\nwhich cargo && cargo --version || echo \"cargo not found on PATH\"","typeGuard":null,"tryCatchPattern":"try { /* start Rust resource */ }\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"Unable to start 'cargo'\"))\n{ /* show install guidance from ex.Message */ }","preventionTips":["Install Rust via rustup on all dev machines and CI images that run the App Host.","Add ~/.cargo/bin (or %USERPROFILE%\\.cargo\\bin) to PATH for the process launching the App Host, including services.","Verify with 'cargo --version' in the same environment that runs the apphost, not just an interactive shell."],"tags":["rust","cargo","process-start","path"],"backgroundTag":"command-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"}