microsoft/aspire · error · DistributedApplicationException

Unable to start 'cargo' to inspect the Rust app

Error message

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}

What it means

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.

Solutions

  1. Install Rust/cargo from https://www.rust-lang.org/tools/install (rustup) and confirm 'cargo --version' works.
  2. 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).
  3. Check the workingDirectory of the Rust resource points at the directory containing Cargo.toml.
  4. Alternatively supply your own Dockerfile for the resource so container builds do not depend on host cargo.

Example fix

// shell — make cargo visible to the apphost process
// before
# cargo only on interactive shell PATH via ~/.cargo/env

// after
export PATH="$HOME/.cargo/bin:$PATH"  # set for the process launching the App Host / systemd unit / CI job
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight check before launching the apphost:
which cargo && cargo --version || echo "cargo not found on PATH"

Try / catch

try { /* start Rust resource */ }
catch (DistributedApplicationException ex) when (ex.Message.Contains("Unable to start 'cargo'"))
{ /* show install guidance from ex.Message */ }

Prevention

When it happens

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

Common situations: 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.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Rust/CargoMetadataReader.cs:92

        foreach (var argument in BuildArguments(manifestPath))
        {
            startInfo.ArgumentList.Add(argument);
        }

        foreach (var (name, value) in environment)
        {
            startInfo.Environment[name] = value;
        }

        using var process = new Process { StartInfo = startInfo };

        try
        {
            process.Start();
        }
        catch (Exception ex)
        {
            throw new DistributedApplicationException(
                $"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}", ex);
        }

        // Drain both redirected streams concurrently so a full pipe cannot block cargo before it exits.
        var stdoutTask = process.StandardOutput.ReadToEndAsync(CancellationToken.None);
        var stderrTask = process.StandardError.ReadToEndAsync(CancellationToken.None);

        using var timeoutSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
        timeoutSource.CancelAfter(s_timeout);

        try
        {
            await process.WaitForExitAsync(timeoutSource.Token).ConfigureAwait(false);
        }
        catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
        {
            TryKillProcess(process);

View on GitHub (pinned to 25830f84bd)