microsoft/aspire · error · DistributedApplicationException
The Rust app ' ' requested the cargo package ' ' with…
Error message
The Rust app '{resourceName}' requested the cargo package '{requestedPackage}' with WithCargoPackage, but 'cargo metadata' reported no such package. Available packages: {FormatPackageNames(metadata)}. What it means
ResolvePackage throws this DistributedApplicationException when WithCargoPackage named a package that 'cargo metadata' does not report in the workspace. The check runs before any build because the debugger needs the executable path up front; otherwise the typo would surface later as an opaque LINQ 'Sequence contains no matching element' error. The message lists all available package names to make the typo obvious.
Solutions
- Correct the name passed to WithCargoPackage to exactly match a package listed in the error message
- Run 'cargo metadata --no-deps' in the app directory to see the actual package names
- Ensure the resource's app directory points at the workspace that actually contains the requested package
Example fix
// before
builder.AddRustApp("app", "../rust-workspace")
.WithCargoPackage("my-server"); // actual package is "my_server"
// after
builder.AddRustApp("app", "../rust-workspace")
.WithCargoPackage("my_server"); Defensive patterns
Strategy: validation
Validate before calling
var names = GetCargoPackageNames(appDir);
if (!names.Contains(requestedPackage)) throw new InvalidOperationException($"Package '{requestedPackage}' not in workspace. Available: {string.Join(", ", names)}"); Type guard
bool PackageExists(CargoMetadata m, string name) => m.Packages.Any(p => p.Name == name);
Try / catch
try { builder.AddRustApp("app", dir).WithCargoPackage(pkg); } catch (DistributedApplicationException ex) when (ex.Message.Contains("reported no such package")) { log.LogError(ex, "Unknown cargo package"); } Prevention
- Copy package names exactly from 'cargo metadata --no-deps' output; watch for hyphens vs underscores
- Update WithCargoPackage names whenever a crate is renamed in Cargo.toml
- Confirm the app directory points at the workspace containing the package
When it happens
Trigger: Calling .WithCargoPackage("<name>") with a name that does not exactly match any package Name reported by 'cargo metadata' for the app's workspace — typos, wrong casing, or referencing a package outside the workspace.
Common situations: Typo in the package name passed to WithCargoPackage; the package lives in a different workspace/repository than the app directory; renaming the crate in Cargo.toml without updating the resource configuration; case mismatch since the comparison is exact.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Aspire.Hosting.Rust requires Cargo 1.71 or later because…
- 'cargo metadata' failed for the Rust app
- 'cargo metadata' for the Rust app
- Unable to read the output of 'cargo metadata' for the Rust…
- Unable to start 'cargo' to inspect the Rust app
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/9aedcfc0f65afc03.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Rust/RustCargoTargetResolver.cs:167
// user at WithCargoBinTarget would send them looking for a target that does not exist.
[] => throw new DistributedApplicationException(
$"Unable to work out which binary the Rust app '{resourceName}' produces: the package '{package.Name}' declares no " +
$"binary targets. Point the app directory at a package with a binary, or select one with WithCargoPackage(\"<name>\")."),
var many => throw new DistributedApplicationException(
$"Unable to work out which binary the Rust app '{resourceName}' produces: the package '{package.Name}' declares " +
$"{many.Count} binary targets. Call WithCargoBinTarget(\"<name>\") to select one.")
};
}
private static CargoPackage ResolvePackage(CargoMetadata metadata, string? requestedPackage, string resourceName)
{
if (requestedPackage is not null)
{
// Reported here rather than left to cargo because this runs before any build: the debugger needs
// the executable path up front, so a typo would otherwise surface as an unexplained
// "Sequence contains no matching element" from LINQ.
return metadata.Packages.FirstOrDefault(p => p.Name == requestedPackage)
?? throw new DistributedApplicationException(
$"The Rust app '{resourceName}' requested the cargo package '{requestedPackage}' with WithCargoPackage, but " +
$"'cargo metadata' reported no such package. Available packages: {FormatPackageNames(metadata)}.");
}
var defaultPackages = metadata.Packages.Where(p => metadata.DefaultMemberIds.Contains(p.Id)).ToList();
if (defaultPackages is [var onlyMember])
{
return onlyMember;
}
// `cargo run` only needs one *runnable* member, so the common workspace shape of an app crate beside
// library crates runs fine. Library-only members are dropped before the choice is called ambiguous.
var runnablePackages = defaultPackages.Where(static p => p.BinTargetNames.Count > 0).ToList();
return runnablePackages switch
{
[var single] => single,View on GitHub (pinned to 25830f84bd)