我有以下的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