{"record":{"id":"8925b33c460ca188","repo":"microsoft/aspire","slug":"unable-to-work-out-which-binary-the-rust-app-resourcename-8925b3","errorCode":null,"errorMessage":"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.","messagePattern":"Unable to work out which binary the Rust app '(.+?)' produces: the package '(.+?)' declares (.+?) binary targets\\. Call WithCargoBinTarget\\(\"<name>\"\\) to select one\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Rust/RustCargoTargetResolver.cs","lineNumber":153,"sourceCode":"\n    private static string ResolveBinaryName(CargoMetadata metadata, string? requestedPackage, string resourceName)\n    {\n        var package = ResolvePackage(metadata, requestedPackage, resourceName);\n\n        if (package.DefaultRun is { Length: > 0 } defaultRun)\n        {\n            return defaultRun;\n        }\n\n        return package.BinTargetNames switch\n        {\n            [var single] => single,\n            // A package with no binary at all is a different mistake from an ambiguous one, and pointing the\n            // user at WithCargoBinTarget would send them looking for a target that does not exist.\n            [] => throw new DistributedApplicationException(\n                $\"Unable to work out which binary the Rust app '{resourceName}' produces: the package '{package.Name}' declares no \" +\n                $\"binary targets. Point the app directory at a package with a binary, or select one with WithCargoPackage(\\\"<name>\\\").\"),\n            var many => throw new DistributedApplicationException(\n                $\"Unable to work out which binary the Rust app '{resourceName}' produces: the package '{package.Name}' declares \" +\n                $\"{many.Count} binary targets. Call WithCargoBinTarget(\\\"<name>\\\") to select one.\")\n        };\n    }\n\n    private static CargoPackage ResolvePackage(CargoMetadata metadata, string? requestedPackage, string resourceName)\n    {\n        if (requestedPackage is not null)\n        {\n            // Reported here rather than left to cargo because this runs before any build: the debugger needs\n            // the executable path up front, so a typo would otherwise surface as an unexplained\n            // \"Sequence contains no matching element\" from LINQ.\n            return metadata.Packages.FirstOrDefault(p => p.Name == requestedPackage)\n                ?? throw new DistributedApplicationException(\n                    $\"The Rust app '{resourceName}' requested the cargo package '{requestedPackage}' with WithCargoPackage, but \" +\n                    $\"'cargo metadata' reported no such package. Available packages: {FormatPackageNames(metadata)}.\");\n        }\n","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Rust/RustCargoTargetResolver.cs#L135-L171","documentation":"ResolveBinaryName throws this DistributedApplicationException when the resolved cargo package declares multiple (ambiguous) binary targets and the user has not selected one. Aspire cannot guess which executable to run or debug, so it fails fast listing the count and instructing the user to disambiguate with WithCargoBinTarget. This differs from the zero-binary-target error: here a valid choice exists, it just was not made.","triggerScenarios":"Adding a RustAppResource whose package's BinTargetNames contains 2+ entries (e.g. multiple [[bin]] sections in Cargo.toml) without calling WithCargoBinTarget or WithCargoPackage to pick one.","commonSituations":"Crates that ship several binaries (cli + server, client + daemon) built from one Cargo.toml; adding a second [[bin]] target and then running the AppHost without updating the resource config.","solutions":["Call .WithCargoBinTarget(\"<name>\") on the resource to select one of the declared binaries","Call .WithCargoPackage(\"<name>\") to route through a specific package first, then select the binary","Merge or remove unneeded [[bin]] targets in Cargo.toml if only one binary is intended"],"exampleFix":"// before\nbuilder.AddRustApp(\"app\", \"../rust-multi-bin\"); // declares 2 bin targets\n// after\nbuilder.AddRustApp(\"app\", \"../rust-multi-bin\")\n       .WithCargoBinTarget(\"my-server\");","handlingStrategy":"validation","validationCode":"var bins = ResolvePackageBinTargetNames(appDir);\nif (bins.Count > 1) Console.WriteLine($\"Ambiguous binaries: {string.Join(\", \", bins)} — call WithCargoBinTarget.\");","typeGuard":"bool HasSingleBinary(CargoPackage p) => p.BinTargetNames.Count == 1;","tryCatchPattern":"try { builder.AddRustApp(\"app\", dir); } catch (DistributedApplicationException ex) when (ex.Message.Contains(\"WithCargoBinTarget\")) { log.LogError(ex, \"Ambiguous cargo bin target\"); }","preventionTips":["Whenever a crate declares multiple [[bin]] targets, always specify WithCargoBinTarget","Audit Cargo.toml for added [[bin]] sections after pulling upstream changes","Prefer explicit WithCargoPackage + WithCargoBinTarget over auto-resolution in CI"],"tags":["rust","cargo","ambiguity","binary-target"],"backgroundTag":"conflicting-config-options","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"}