' System.Reflection.TargetInvocationException'调用Activator.CreateInstance()时

时间:2015-04-12 21:53:47

标签: c# asp.net webforms

我收到此错误:

A first chance exception of type 'System.Reflection.TargetInvocationException'
occurred in mscorlib.dll

还有:

Exception has been thrown by the target of an invocation.

运行此方法时,CreateInstance(Type.GetType(instantiationString), parameters)调用上发生错误:

public static Report instantiateReport(ReportInfo reportInfo)
{
    string instantiationString;
    Report reportToReturn;
    ReportInfo[] parameters = new ReportInfo[1];
    parameters[0] = reportInfo;

    instantiationString = reportInfo.Report.InstantiationPath;
    reportToReturn = (Report)Activator.CreateInstance(Type.GetType(instantiationString), parameters);

    return reportToReturn;
}

ReportInfo只是一个自定义类,其中包含帮助我构建我试图实例化的报表的变量,当我调查它时,一切都很好。 instantiationString只是帮助我了解在调用时尝试创建哪个报告,这样我就可以使用Type.GetType()方法。我真的不知道这是什么样的错误或可能出错的地方。我研究了一下,但没有得到任何有用的答案,所以任何帮助都表示赞赏。

编辑查看内部异常后,我收到Object reference not set to an instance of an object.条消息。这很奇怪,因为ReportInfoGetType()方法都没有空引用。假设ReportInfo中的一个变量为空,是否会导致问题?应该不对吗?

FIXED 在深入研究内部异常的堆栈跟踪后,我发现存在一些冲突的代码导致其他地方出现问题。问题解决了。

0 个答案:

没有答案
相关问题