RicoSuter/NSwag · error · InvalidOperationException
The parameter '" + Name + "' is required.
Error message
The parameter '" + Name + "' is required.
What it means
When a required argument's value is missing on the command line, NConsole prompts interactively via consoleHost.ReadValue. If the user (or a non-interactive host) answers '[default]', the attribute falls back to the property's current value — but when IsRequired is true there is no acceptable default, so it throws InvalidOperationException naming the required parameter.
Solutions
- Provide the required argument explicitly on the command line (/name:value) so no prompt occurs.
- If the argument should have a fallback, set IsRequired = false and supply a default property value in the command class.
- In non-interactive environments, feed the value via stdin/variables instead of relying on the prompt.
- Check the .nswag/CI config that the variable mapped to this argument isn't empty.
Example fix
// before nswag openapi2csclient /output:Client.cs // input prompted, [default] answered // after nswag openapi2csclient /input:swagger.json /output:Client.cs
Defensive patterns
Strategy: validation
Validate before calling
var missing = requiredArgs.Where(a => !CommandLineArgs.ContainsKey(a)).ToList();
if (missing.Any())
throw new ArgumentException($"Missing required arguments: {string.Join(", ", missing)}. Supply them on the command line; do not rely on interactive prompts."); Try / catch
try { result = processor.Process(args); }
catch (InvalidOperationException ex) when (ex.Message.Contains("is required")) { Console.Error.WriteLine($"Supply the missing option: {ex.Message}"); Environment.Exit(2); } Prevention
- Always pass required options explicitly in scripts/CI — never rely on the interactive prompt
- Run non-interactive CI with all arguments supplied via stdin or flags
- Mark IsRequired = false only when a real default exists on the property
- Validate required inputs in your wrapper script before invoking NSwag
When it happens
Trigger: Running a command without a required argument while IsRequired = true on its [Argument] attribute, and the interactive prompt returns '[default]' (e.g. piped/redirected stdin, CI with no TTY supplying the default sentinel) so no real value is captured.
Common situations: Forgetting /input or /output style required options in scripts; running NSwag in CI where interactive prompts read an empty/auto-answered stdin; marked IsRequired but never supplying the value in an .nswag variables section.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
AI-assisted analysis of RicoSuter/NSwag@63daf8fcc3 (2026-09-14).
Data as JSON: /api/errors/09f4774da57765c5.
Report an issue: GitHub.
Appendix: source
Thrown at src/NSwag.Commands/NConsole/ArgumentAttribute.cs:71
{
return ArgumentAttributeBase.ConvertToType(value, property.PropertyType);
}
if (AcceptsCommandInput && input != null)
return input;
if (!ArgumentAttribute.IsInteractiveMode(args) && !IsRequired)
return property.CanRead ? property.GetValue(command) : null;
if (ShowPrompt)
{
value = consoleHost.ReadValue(GetFullParameterDescription(property, command));
if (value == "[default]")
{
if (!IsRequired)
return property.CanRead ? property.GetValue(command) : null;
throw new InvalidOperationException("The parameter '" + Name + "' is required.");
}
return ArgumentAttributeBase.ConvertToType(value, property.PropertyType);
}
else
return property.CanRead ? property.GetValue(command) : null;
}
private static bool IsInteractiveMode(string[] args)
{
return args.Length == 0;
}
private bool TryGetPositionalArgumentValue(string[] args, ref string used, out string value)
{
if (Position > 0 && Position < args.Length)
{
value = args[Position];View on GitHub (pinned to 63daf8fcc3)