私のコードは
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タイプはそうではありません