microsoft/aspire · error · DistributedApplicationException
Unable to work out which binary the Rust app
Error message
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>"). What it means
ResolveBinaryName maps a cargo package to the executable it produces, and throws this DistributedApplicationException when the resolved package declares zero binary targets (empty BinTargetNames). Without a bin target there is no executable path for run/debug, and suggesting WithCargoBinTarget would point at a target that cannot exist, so the message instead directs the user to a package that actually produces a binary. It is thrown up front so the failure happens before any build attempt.
Solutions
- Point the resource at a directory whose package contains a binary target (src/main.rs or a [[bin]] section)
- Call .WithCargoPackage("<name>") to select a workspace package that has a binary target
- Add a [[bin]] target or src/main.rs to the crate if it is supposed to produce an executable
Example fix
// before
builder.AddRustApp("app", "../rust-lib"); // lib-only crate
// after
builder.AddRustApp("app", "../rust-workspace")
.WithCargoPackage("my-server"); // package with a binary target Defensive patterns
Strategy: validation
Validate before calling
var meta = RunCargoMetadata(appDir);
if (meta.Packages.All(p => p.BinTargetNames.Count == 0)) throw new InvalidOperationException("No package in the workspace declares a binary target."); Type guard
bool HasRunnablePackage(CargoMetadata m) => m.Packages.Any(p => p.BinTargetNames.Count > 0);
Try / catch
try { builder.AddRustApp("app", dir); } catch (DistributedApplicationException ex) when (ex.Message.Contains("declares no")) { log.LogError(ex, "Rust package has no bin target"); } Prevention
- Ensure the target crate has src/main.rs or a [[bin]] section before wiring it up
- Run 'cargo metadata --no-deps' and check for bins before configuring the resource
- Use WithCargoPackage to point at a known runnable crate in multi-crate workspaces
When it happens
Trigger: Adding a RustAppResource whose app directory resolves (via 'cargo metadata') to a library-only crate, with no WithCargoPackage or WithCargoBinTarget specified and zero packages with binary targets in the default workspace members.
Common situations: Pointing the Rust integration at a src/ directory containing only library crates (e.g. a shared lib crate); a Cargo.toml with no [[bin]] section and no src/main.rs; workspace layouts where the default member picked is lib-only.
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
- Unable to work out which binary the Rust app
- Aspire.Hosting.Rust requires Cargo 1.71 or later because…
- 'cargo metadata' failed for the Rust app
- 'cargo metadata' for the Rust app
- The Rust app ' ' requested the cargo package ' ' with…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/5121c080d6e0e566.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Rust/RustCargoTargetResolver.cs:150
_ => profile
};
}
private static string ResolveBinaryName(CargoMetadata metadata, string? requestedPackage, string resourceName)
{
var package = ResolvePackage(metadata, requestedPackage, resourceName);
if (package.DefaultRun is { Length: > 0 } defaultRun)
{
return defaultRun;
}
return package.BinTargetNames switch
{
[var single] => single,
// A package with no binary at all is a different mistake from an ambiguous one, and pointing the
// 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 " +View on GitHub (pinned to 25830f84bd)