0

所以这是我的 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>哪里?

谢谢您的帮助。

4

1 回答 1

1

After searching point by point everything, I found that the error was in the requestW class where the "The index was off limits. It should not be negative and must be less than the size of the collection \ r \ nName parameter . StartIndex" error was. ( After checking everything point by point, it seems that this error comes again inside of my class where I'm trying to read an Internet website.)

In this class, I have a part who goes from one side of a <tbody to another and after decomposition I see that the StartIndex value is not positive but negative, which throw an exception.

So the problem was not in the List<Account> li = (List<Account>)method.Invoke(null, arguments); itself but in the method class were my requestW is called and gives the Exception. Thank you everyone for helping me to solve my problem :)

于 2016-02-15T10:36:17.613 回答