所以这是我的 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
}
这是类 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 系统来理解,他们告诉我:
“索引超出限制。它不应为负数,并且必须小于集合 \r\nName 参数的大小。StartIndex”
但我还是不明白这是什么意思……问题出在List<Account>
哪里?
谢谢您的帮助。