首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MethodInfo.Invoke Throw c#

MethodInfo.Invoke Throw c#
EN

Stack Overflow用户
提问于 2016-02-15 09:34:03
回答 1查看 776关注 0票数 0

所以这是我的TargetInvocationException的问题。

此错误发生在带有MethodInfo method.Invoke(null, arguments);的行上。

如果我在做一个比我更早的人做的代码,在2014年,它应该是起作用的,但它不是。在整个周末的搜索之后,我没有发现问题。请不要犹豫地向我询问关于我所拥有的代码的更多信息,也许问题来自其他地方。

在主程序中,它看起来如下(并不是所有的代码,有些部分在这些行之间,但您不需要它们):

代码语言:javascript
复制
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
}

这是班级帐户:

代码语言:javascript
复制
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>有问题吗?

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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被调用并给出了异常。谢谢大家帮助我解决问题:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35405733

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档