Getting TargetInvocationException using Parser command line library

Update 2: It seems that this library is not Compact-Framework at all, and I get other exceptions - I leave this question as it is, but I think you should not waste time answering. I opened another question for the suggestion of other compact framework libraries.


Use parser library for command line .

I use the following code to determine command line arguments:

[Option("d", "duration", Required = true,  HelpText = "text.")]
public int duration = DEFAULT_TEST_DURATION;

[Option("s", "sleeptime", HelpText = "text.")]
public int sleepTime = DEFAULT_TEST_SLEEP;

[Option("p", "pause", HelpText = "text.")]
public int iterInterval = DEFAULT_TEST_INTERVAL;

[Option(null, "nosync", HelpText = "text.")]
public bool nosync = false;

[Option(null, "nosuspend", HelpText = "text.")]
public bool nosuspend = false;

[Option(null, "reboot", HelpText = "text.")]
public bool reboot = false;

[HelpOption(HelpText = "Dispaly this help screen.")]
public string GetUsage()
{
    HelpText help = new HelpText("MyExe");
    help.AddPreOptionsLine("Usage: MyExe -d 500 -s 20 -p 10 --nosync");
    help.AdditionalNewLineAfterOption = true;
    help.AddOptions(this);
    return help;
}

I get a TargetInvocationException in help.AddOptions(this). Trace:

System.Reflection.TargetInvocationException was unhandled
  Message="TargetInvocationException"
  StackTrace:
       at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess, StackCrawlMark& stackMark)

If the rest is necessary, comment and I will send it.

MethodInfo, , , . , , .

, , . , CF3.5, .

VS2008.

Update: , , .

, MethodInfo CF3.5 ReturnParameter, .

InnerException MissingMethodException

.

+3
2

Compact-Framework

0

InnerException :

try{
    help.AddOptions(this);
} catch (TargetInvocationException e) {
    Console.WriteLine(e.InnerException);
}

P.S: , ?

+1

Source: https://habr.com/ru/post/1732991/


All Articles