我最初使用以下方法 - 效果很好
var obj = Activator.CreateInstance("MyProject","MyProject.MyImpl");
现在我在上面的行中遇到错误,错误是:
Exception has been thrown by the target of an invocation.
关于可能出现问题的任何建议?
我最初使用以下方法 - 效果很好
var obj = Activator.CreateInstance("MyProject","MyProject.MyImpl");
现在我在上面的行中遇到错误,错误是:
Exception has been thrown by the target of an invocation.
关于可能出现问题的任何建议?
最简单的方法是在类的构造函数中设置断点MyImpl
并对其进行调试。
您可能遇到的一个棘手问题是,如果异常实际上不是由构造函数直接抛出,而是由某个字段初始化程序抛出。
例如,即使没有可以抛出任何东西的显式构造函数,以下内容也会导致您描述的行为。
public class MyImpl
{
private int something = ThisMethodThrows();
private int ThisMethodThrows()
{
throw new Exception();
}
}
对象的构造函数中抛出异常。在 Visual Studio 中打开异常,当该构造函数抛出时它应该会中断。