我有以下的C#類和2層的構造函數:構造 'GTS.CSVImport_HR_Standard' 未找到
public class CSVImport_HR_Standard : CSVImport
{
int fPropertyID;
public CSVImport_HR_Standard()
{
}
public CSVImport_HR_Standard(string oActivationParams)
{
this.fPropertyID = Convert.ToInt32(oActivationParams);
}
和父類:
public class CSVImport
{
沒有任何構造函數。
類正在從下面的方法調用:
private object CreateCommandClassInstance(string pCommandClass, string pActivationParams.ToArray())
{
List<object> oActivationParams = new List<object>();
// In the current implementation we assume only one param of type int
if (pActivationParams != "")
{
Int32 iParam = Convert.ToInt32(pActivationParams);
oActivationParams.Add(iParam);
}
object oObject = Activator.CreateInstance(Type.GetType("GTS." + pCommandClass), oActivationParams);
return(oObject);
}
凡
pCommandClass = GTS.CSVImport_HR_Standard
,但我得到了以下錯誤:
Constructor on type 'GTS.CSVImport_HR_Standard' not found.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: Constructor on type 'GTS.CSVImport_HR_Standard' not found.
至於我能看到構造函數是正確的,它傳遞了所有正確的參數,那爲什麼它給了我這個錯誤?
從我讀過,我最好的猜測是,這是值得做的線:
object oObject = Activator.CreateInstance(Type.GetType("GTS." + pCommandClass), oActivationParams);
但我不知道什麼可能會造成一個問題,因爲它似乎在構造函數是正確的?
我已經試過了,但它不工作 – Alex 2015-02-24 13:05:12
你試試我的最後一個音符?嘗試將'pActivationParams'設置爲'null'。 – 2015-02-24 13:06:31
是的,我嘗試使用ToArray,也改變了構造函數接收數組,但它仍然給出了相同的錯誤 – Alex 2015-02-24 13:12:01