[英]MethodInfo.Invoke Throw TargetInvocationException c#
所以这是我与TargetInvocationException有关的问题。
在使用MethodInfo method.Invoke(null, arguments);
的行上发生此错误MethodInfo method.Invoke(null, arguments);
仅供参考,我正在编写某人在我之前编写的代码,2014年应该可以,但事实并非如此。 在整个周末搜索之后,我没有发现问题。 不要犹豫,询问我有关我的代码的更多信息,也许问题出在其他地方。
在主程序中,它看起来像这样(不是所有代码,某些部分在这些行之间,但是您不需要它们):
static void Main (string[] args)
{
[... Code before]
object[] arguments = { popup };
MethodInfo method;
CodeCompiler cc = new CodeCompiler();
method = cc.CompileCode(fichier, "test", "RequestWeb", "requestW", true, arguments);
List<Account> li = (List<Account>)method.Invoke(null, arguments); // TargetInvocationException Here is the error
}
这是Account类:
public class Account
{
virtual public string libelle { get; set; }
virtual public List<AccountStat> listR { get; set; }
public Account()
{
this.listR = new List<AccountStat>(); // This go to another class where List<AccountStat> is defined
}
}
我试图通过InnerException系统了解谁告诉我:
“索引超出限制。它不能为负,并且必须小于collection \\ r \\ nName参数的大小。StartIndex”
但我仍然不明白这是什么意思... List<Account>
是否有问题?
谢谢您的帮助。
逐点搜索之后,我发现错误出在requestW
类中,其中"The index was off limits. It should not be negative and must be less than the size of the collection \\ r \\ nName parameter . StartIndex"
错误是。 (在逐点检查所有内容之后,似乎该错误再次出现在我尝试阅读Internet网站的班级内部。)
在这个类中,我有一部分从<tbody
一侧延伸到另一侧,分解之后,我看到StartIndex
值不是正数而是负数,这引发了异常。
所以问题不在List<Account> li = (List<Account>)method.Invoke(null, arguments);
本身,但在method
类中是我的requestW
被调用并给出了异常。 谢谢大家帮助我解决我的问题:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.