我最初使用下面的方法 - 這是工作的罰款Activator.CreateInstance返回錯誤現在
var obj = Activator.CreateInstance("MyProject","MyProject.MyImpl");
現在,我在上面的線得到一個錯誤,並且錯誤是:
Exception has been thrown by the target of an invocation.
有什麼可能會出錯的建議?
我最初使用下面的方法 - 這是工作的罰款Activator.CreateInstance返回錯誤現在
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();
}
}
在對象的構造函數中引發異常。 Turn exceptions on in Visual Studio當構造函數拋出時它會中斷。
那麼,如果你看看內部異常,它可能會告訴你什麼是錯的。一定要查看*所有*的例外信息。 –
'MyImpl'在構造函數中拋出一個異常。 – Will