dotnet/yarp · error · ArgumentException
Unexpected arg '{remainder[1]}'.
Error message
Unexpected arg '{remainder[1]}'. What it means
Thrown by CommandLineArgs.ParseRemainder when the trailing positional arguments contain more than one token. The parser only expects a single positional value (the scenario name); any extra positional token is rejected with the offending value interpolated.
Source
Thrown at testassets/TestClient/CommandLineArgs.cs:62
}
if (i < args.Length)
{
return ParseRemainder(result, args.AsSpan().Slice(i));
}
return result;
static CommandLineArgs ParseRemainder(CommandLineArgs result, Span<string> remainder)
{
if (remainder.Length == 0)
{
throw new ArgumentException("Expected additional args.");
}
if (remainder.Length > 1)
{
throw new ArgumentException($"Unexpected arg '{remainder[1]}'.");
}
result.Scenario = remainder[0];
return result;
}
}
public static void ShowHelp()
{
Console.WriteLine("ReverseProxy SampleClient.\n");
Console.WriteLine("--scenario <name>, -s <name>: Runs only the specified scenario.");
Console.WriteLine(
"--target <uri>, -t <uri>: Sets the target uri. By default, 'https://localhost:1443/' is used.");
Console.WriteLine("--help, -h, -?, /?: Shows this help information.");
}
}
View on GitHub (pinned to bd11867bee)
Solutions
- Pass exactly one positional scenario name, or use --scenario/-s to name it explicitly.
- Quote any argument containing spaces.
- Remove unrecognized flags; only --scenario/-s, --target/-t, and --help/-h/-?//? are recognized.
Example fix
// before dotnet TestClient ScenarioA ScenarioB // after dotnet TestClient --scenario ScenarioA
Defensive patterns
Strategy: validation
Validate before calling
// Validate argv shape before parsing.
var positional = args.Where(a => !a.StartsWith('-')).ToList();
if (positional.Count > 1)
throw new ArgumentException($"Only one positional scenario argument is allowed; got {positional.Count}."); Prevention
- Pass the scenario via --scenario/-s rather than positionally to avoid ambiguity.
- Quote arguments that contain spaces.
- Remember only --scenario, --target, and --help are recognized; unknown flags fall through to positional.
When it happens
Trigger: Running the SampleClient with two or more positional arguments, e.g. `TestClient ScenarioA ScenarioB`, or mixing an unrecognized flag that falls through the switch and becomes positional.
Common situations: Typing two scenario names; passing an unquoted argument containing a space that splits into two tokens; an unrecognized --flag that the switch does not consume so it rolls into the remainder.
Related errors
- Expected additional args.
- Expected status 409 Conflict!
- Expected status 101 Switching Protocols!
- Read {read} bytes, expected 0 after sending Goodbye.
- Read {read} bytes, expected 1.
AI-assisted analysis of dotnet/yarp@bd11867bee (2026-08-13).
Data as JSON: /api/errors/5f3522948dc7a42f.
Report an issue: GitHub.