开发者

Getting TargetInvocationException using Command Line Parser Library

开发者 https://www.devze.com 2022-12-20 19:31 出处:网络
Update 2: Seems that this library is not Compact-Framework aware at all and I keep getting other exceptions - I am leaving this question as is, but I think you should not waste time on answering it.

Update 2: Seems that this library is not Compact-Framework aware at all and I keep getting other exceptions - I am leaving this question as is, but I think you should not waste time on answering it.

I opened another question for suggestion of other compact-framework friendly libraries.


Using the Command Line Parser Library.

I am using the following code to defi开发者_如何转开发ne the 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 am getting TargetInvocationException on help.AddOptions(this). The trace is:

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 needed please comment and I will post it.

I could not find in the documentation for MethodInfo that it throws this exception and so I can't see why I am getting it. I use this the same way the sample of the library does and I don't get an exception in the sample application.

I guess that the reason lies in the fact that I am compiling this for a smart device. Probably has to do with support in the CF3.5, but I am not sure.

Using VS2008.

Update: I should have mentioned that the sample runs on the full framework whereas my app runs on the compact version.

I noticed that MethodInfo in CF3.5 does not have a ReturnParameter property as opposed to the full framework version.

Also as an answer to the answer below the InnerException gives MissingMethodException

Thanks.


The InnerException property should give you more details:

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

P.S: You are using this library, right?


the library is not designed for the Compact-Framework

0

精彩评论

暂无评论...
验证码 换一张
取 消