日期:2014-05-17 浏览次数:21434 次
考试系统用的是三层,抽象工厂+反射,调试系统的时候出现了这样一个错误:是在使用缓存处抛异常

并且查看返回的借口的值为null,然后就出现这个错误,接口没有创建成功。
/// <summary>
		/// 创建QuestionTypesDAL数据层接口。题型实体表
 
		/// </summary>
		public static ExamSystemV3.IDAL.IQuestionTypesDAL CreateQuestionTypesDAL()
		{
			string ClassNamespace = AssemblyPath +".QuestionTypesDAL";
			object objType=CreateObject(AssemblyPath,ClassNamespace);
			return (ExamSystemV3.IDAL.IQuestionTypesDAL)objType;
		}
       
//使用缓存
		private static object CreateObject(string AssemblyPath,string classNamespace)
		{			
			object objType = DataCache.GetCache(classNamespace);//从缓存中读取
			if (objType == null)
			{
				try
				{
				      //反射的创建				
					objType = Assembly.Load(AssemblyPath).CreateInstance(classNamespace);	DataCache.SetCache(classNamespace, objType);// 写入缓存
				}
				catch//(System.Exception ex)
				{
					//string str=ex.Message;// 记录错误日志
				}
			}
			return objType;
		}
从网上搜索了一下,查看自己的web.config文件,
<!--数据访问层程序集名称 -->
    <add key="ExamSystemV3.SQLServerDAL" value="Maticsoft.SQLServerDAL" />    

项目的属性名称要和程序集的名称不一致导致了这个问题。
修改web.config文件后
<!--数据访问层程序集名称 -->
     <add key="DAL" value="ExamSystemV3.SQLServerDAL" />