我的代码是
type = Type.GetType(key);
我传递的键是命名空间限定名称。
我的代码在 BusinessLayer 中。我正在创建 DataAccessLayer 的一个实例。DataAccessLayer 引用已添加到 BusinessLayer。
我收到错误消息“无法从程序集'BusinessLayer,Version = 1.9.3.0,Culture = Neutral,PublicKeyToken = null'加载类型'Catalyst.DAL.ExamDAO.CExamDAO'。” .
我应该怎么做才能明确指定该类来自 DataAccessLayer ?
关键值是“Catalyst.DAL.ExamDAO.CExamDAO”
编辑 :
我的实际代码是
public static object getClassInstance(string key, params object[] constructorArgs)
{
string assemblyPath = null;
string customClassName = null;
DataSet objDataset = getAssemblyInfo(key);
if (objDataset != null && objDataset.Tables.Count > 0 && objDataset.Tables[0].Rows.Count > 0)
{
assemblyPath = objDataset.Tables[0].Rows[0]["ACA_ASSEMBLY_PATH"].ToString();
customClassName = objDataset.Tables[0].Rows[0]["ACA_CLASS_NAME"].ToString();
}
Assembly assembly;
Type type;
if (assemblyPath != null && assemblyPath != string.Empty)
{
assembly = Assembly.LoadFile(assemblyPath);
type = assembly.GetType(customClassName);
}
else // if no customisation
{
type = Type.GetType(key);
}
object classInstance = constructorArgs == null ? Activator.CreateInstance(type) : Activator.CreateInstance(type, constructorArgs);
if (classInstance == null) throw new Exception("broke");
return classInstance;
}
如果没有自定义,我正在尝试加载默认类。方法在 BO 中。如果我将密钥作为任何 Bo 类型的命名空间限定名称传递,它将转换。但是DAO类型它不会