工厂模式DALFactory的反射问题
protected static string path = ConfigurationManager.AppSettings["WebDAL"];
public static TUserIDAL CreateTUserIDAL()
{
string classname = path + ".TUser" + daltype;
TUserIDAL A = (TUserIDAL)Assembly.Load(path).CreateInstance(classname);
return A;
}
return 的值A一直为空,查了很长时间,但返回值一直为“null”,请大家帮帮忙path和className和daltype的值也都取的到,classname得到的是:SqlServerDAL.TUsersInfoSqlServerDAL是对的 ,但return 的值A一直为空,请问怎么解决呢?
------解决方案-------------------- 试一下
Type t = typeof(TUserIDAL);
Type subt = Type.GetType(String.Format("{0},{1}", classname, t.Assembly.FullName));
TUserIDAL A =Activator.CreateInstance<subt>();------解决方案-------------------- 检查Bin目录下是否存在该DLL
------解决方案-------------------- 引用: 试一下
Type t = typeof(TUserIDAL);
Type subt = Type.GetType(String.Format("{0},{1}", classname, t.Assembly.FullName));
TUserIDAL A =Activator.CreateInstance<subt>();
要学会一步一步排错的方法
另外
还是用Ioc吧~~~
比工厂好多了~