所以这是我的TargetInvocationException的问题。
此错误发生在带有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
}这是班级帐户:
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系统来理解谁告诉我:
“索引是禁止使用的。它不应该是负值,必须小于集合\r\ nName参数的大小。StartIndex”
但我还是不明白这是什么意思..。List<Account>有问题吗?
谢谢你的帮助。
发布于 2016-02-15 10:36:17
在逐点搜索所有内容之后,我发现错误在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"错误就在该类中。(在逐点检查所有内容之后,似乎这个错误再次出现在我的课堂上,我正在尝试阅读一个互联网网站。)
在这个类中,我有一个部分从<tbody的一边到另一边,分解后我看到StartIndex值不是正的而是负的,这会抛出一个异常。
所以问题不是在List<Account> li = (List<Account>)method.Invoke(null, arguments);本身,而是在method类中,我的requestW被调用并给出了异常。谢谢大家帮助我解决问题:)
https://stackoverflow.com/questions/35405733
复制相似问题