j-maly / CommandLineParser

Command line parser. Declarative arguments support. Rich set of argument types (switches, enums, files, etc...). Mutually exclusive arguments validations.
MIT License
137 stars 30 forks source link

RegexValueArgumentAttribute(char shortName, string longName, string pattern) constructor declaration error #79

Closed dmagician038 closed 2 years ago

dmagician038 commented 2 years ago

Assigning value to _argumentType causing exception:

System.Reflection.TargetException HResult=0x80131603 Message=Object does not match target type. Source=System.Private.CoreLib StackTrace: at System.Reflection.RuntimeMethodInfo.InvokeOneParameter(Object obj, BindingFlags invokeAttr, Binder binder, Object parameter, CultureInfo culture) at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) at System.Reflection.PropertyInfo.SetValue(Object obj, Object value) at ShutDown.CommandLineParser.TypeExtensions.SetPropertyValue(Type type, String propertyName, Object target, Object value) in ...\src\CommandLineArgumentsParser\Arguments\TypeExtensions.cs:line 58

This exception was originally thrown at this call stack: ShutDown.CommandLineParser.TypeExtensions.SetPropertyValue(System.Type, string, object, object) in TypeExtensions.cs

assignment of _argumentType should be RegexValueArgument and not RegexValueArgumentAttribute.

StefH commented 2 years ago

@dmagician038 Can you please provide a full working example (console app)?

dmagician038 commented 2 years ago

Attached a basic project.

console app.zip

  1. The 1st test Test1() is working OK.
  2. The 2nd test Test2() is throwing exception.

BTW, I've fixed it on copied code from your repo - as described in my OP

StefH commented 2 years ago

https://github.com/j-maly/CommandLineParser/pull/80

StefH commented 2 years ago

Hello @dmagician038, this issue is fixed, I'll release a new NuGet soon.

dmagician038 commented 2 years ago

Thank you!