You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose you have two immutable options classes, one of which defines some required values:
[Verb("create",HelpText="Create a new migration.")]publicclassCreateMigrationOptions{publicCreateMigrationOptions(stringname){Name=name;}[Value(0,HelpText="The optional name of the migration to create.")]publicstringName{get;}}[Verb("add",HelpText="Add a new script to a migration.")]publicclassAddScriptOptions{publicAddScriptOptions(stringmigration,stringscript){Migration=migration;Script=script;}[Value(0,Required=true,HelpText="The name of the migration to modify.")]publicstringMigration{get;}[Value(1,Required=true,HelpText="The name of the script to add.")]publicstringScript{get;}}
When parsing command line arguments that invoke the second verb, but without the required options, a ParameterCountMismatch exception is thrown:
System.Reflection.TargetParameterCountException: Parameter count mismatch.
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at CommandLine.Core.InstanceBuilder.<>c__DisplayClass0_2`1.<Build>b__23()
at CommandLine.Core.InstanceBuilder.<>c__DisplayClass0_0`1.<Build>b__7()
at CommandLine.Core.InstanceBuilder.Build[T](Maybe`1 factory, Func`3 tokenizer, IEnumerable`1 arguments, StringComparer nameComparer, Boolean ignoreValueCase, CultureInfo parsingCulture, IEnumerable`1 nonFatalErrors)
at CommandLine.Core.InstanceChooser.MatchVerb(Func`3 tokenizer, IEnumerable`1 verbs, IEnumerable`1 arguments, StringComparer nameComparer, CultureInfo parsingCulture, IEnumerable`1 nonFatalErrors)
at CommandLine.Core.InstanceChooser.<>c__DisplayClass0_0.<Choose>b__0()
at CommandLine.Core.InstanceChooser.Choose(Func`3 tokenizer, IEnumerable`1 types, IEnumerable`1 arguments, StringComparer nameComparer, CultureInfo parsingCulture, IEnumerable`1 nonFatalErrors)
at CommandLine.Parser.ParseArguments(IEnumerable`1 args, Type[] types)
at CommandLine.ParserExtensions.ParseArguments[T1,T2,T3,T4,T5,T6,T7](Parser parser, IEnumerable`1 args)
at Snorri.Program.ExecuteCommands(IResolutionRoot kernel, IEnumerable`1 args) in e:\Users\niels\Documents\Visual Studio 2015\Projects\Snorri\src\Snorri\Program.cs:line 78
at Snorri.Program.<>c__DisplayClass1_0.<Main>b__0(IKernel kernel) in e:\Users\niels\Documents\Visual Studio 2015\Projects\Snorri\src\Snorri\Program.cs:line 28
at Snorri.Program.WithDependencies(Action`1 executeCommands) in e:\Users\niels\Documents\Visual Studio 2015\Projects\Snorri\src\Snorri\Program.cs:line 127
at Snorri.Program.Main(String[] args) in e:\Users\niels\Documents\Visual Studio 2015\Projects\Snorri\src\Snorri\Program.cs:line 28
If you change the AddScriptOptions to no longer be immutable, or if you remove the CreateMigrationOptions class from the call to ParseArguments, then there is no exception thrown, and the parsed.Errors enumerable is populated (correctly noting that a required value was missing).
Thus, throwing an exception in this case feels like it may be a bug.
The text was updated successfully, but these errors were encountered:
I have simpler reproduction of this issue. The following code throws System.Reflection.TargetParameterCountException: Parameter count mismatch. exception in Main when run without parameters.
Thursday Mar 02, 2017 at 13:36 GMT
Originally opened as gsscoder/commandline#419
I am using CommandLineParser 2.1.1-beta.
Suppose you have two immutable options classes, one of which defines some required values:
When parsing command line arguments that invoke the second verb, but without the required options, a ParameterCountMismatch exception is thrown:
Here is the stack trace:
If you change the
AddScriptOptions
to no longer be immutable, or if you remove theCreateMigrationOptions
class from the call toParseArguments
, then there is no exception thrown, and theparsed.Errors
enumerable is populated (correctly noting that a required value was missing).Thus, throwing an exception in this case feels like it may be a bug.
The text was updated successfully, but these errors were encountered: