{"record":{"id":"00e1367f9102d337","repo":"microsoft/aspire","slug":"unable-to-work-out-which-binary-the-rust-app-resourcename-00e136","errorCode":null,"errorMessage":"Unable to work out which binary the Rust app '{resourceName}' produces: 'cargo metadata' reported {runnablePackages.Count} default workspace members with a binary target. Call WithCargoPackage(\"<name>\") to select one. Available packages: {FormatPackageNames(metadata)}.","messagePattern":"Unable to work out which binary the Rust app '(.+?)' produces: 'cargo metadata' reported (.+?) default workspace members with a binary target\\. Call WithCargoPackage\\(\"<name>\"\\) to select one\\. Available packages: (.+?)\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Rust/RustCargoTargetResolver.cs","lineNumber":186,"sourceCode":"                    $\"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\n        var defaultPackages = metadata.Packages.Where(p => metadata.DefaultMemberIds.Contains(p.Id)).ToList();\n\n        if (defaultPackages is [var onlyMember])\n        {\n            return onlyMember;\n        }\n\n        // `cargo run` only needs one *runnable* member, so the common workspace shape of an app crate beside\n        // library crates runs fine. Library-only members are dropped before the choice is called ambiguous.\n        var runnablePackages = defaultPackages.Where(static p => p.BinTargetNames.Count > 0).ToList();\n\n        return runnablePackages switch\n        {\n            [var single] => single,\n            _ => throw new DistributedApplicationException(\n                $\"Unable to work out which binary the Rust app '{resourceName}' produces: 'cargo metadata' reported \" +\n                $\"{runnablePackages.Count} default workspace members with a binary target. Call WithCargoPackage(\\\"<name>\\\") to select one. \" +\n                $\"Available packages: {FormatPackageNames(metadata)}.\")\n        };\n    }\n\n    private static string FormatPackageNames(CargoMetadata metadata)\n        => metadata.Packages is { Count: > 0 } packages\n            ? string.Join(\", \", packages.Select(static p => $\"'{p.Name}'\"))\n            : \"none\";\n}\n","sourceCodeStart":168,"sourceCodeEnd":198,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Rust/RustCargoTargetResolver.cs#L168-L198","documentation":"ResolvePackage throws this DistributedApplicationException when no WithCargoPackage was specified and the workspace's default members contain more than one package with a binary target, making the choice ambiguous (library-only members are filtered out first). Aspire refuses to guess which executable the resource should run, and the message includes the full package list plus the WithCargoPackage remedy. It fails before any build so the fix is cheap.","triggerScenarios":"Adding a RustAppResource on a workspace where 2+ default-member crates have bin targets (e.g. a workspace with both a server and a cli crate), without calling WithCargoPackage or WithCargoBinTarget. Count of 0 goes through a different path.","commonSituations":"Growing a single-crate directory into a multi-cargo workspace and then running the AppHost; vendoring extra runnable crates into the workspace; cloning a monorepo workspace where the resource previously auto-resolved to the only binary crate.","solutions":["Call .WithCargoPackage(\"<package-name>\") on the resource to pick the intended runnable package","Use .WithCargoBinTarget(\"<name>\") if the desired package was already resolved but has several binaries","Restrict the workspace's default-members in the root Cargo.toml so only one runnable crate is a default member"],"exampleFix":"// before\nbuilder.AddRustApp(\"app\", \"../rust-workspace\"); // server + cli both have bins\n// after\nbuilder.AddRustApp(\"app\", \"../rust-workspace\")\n       .WithCargoPackage(\"server\");","handlingStrategy":"validation","validationCode":"var runnable = GetDefaultMembersWithBins(appDir);\nif (runnable.Count > 1) Console.WriteLine($\"Ambiguous workspace packages: {string.Join(\", \", runnable)} — call WithCargoPackage.\");","typeGuard":"bool HasSingleRunnableDefaultMember(CargoMetadata m) => m.Packages.Count(p => m.DefaultMemberIds.Contains(p.Id) && p.BinTargetNames.Count > 0) == 1;","tryCatchPattern":"try { builder.AddRustApp(\"app\", dir); } catch (DistributedApplicationException ex) when (ex.Message.Contains(\"default workspace members\")) { log.LogError(ex, \"Ambiguous cargo workspace\"); }","preventionTips":["Always specify WithCargoPackage in multi-crate workspaces instead of relying on auto-resolution","Set default-members in the root Cargo.toml to keep auto-resolution deterministic","Re-check resource config after adding new runnable crates to the workspace"],"tags":["rust","cargo","ambiguity","workspace"],"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"}