当前位置:编程学习 > C#/ASP.NET >>

{"未能加载文件或程序集“SQLServerDAL”或它的某一个依赖项。系统找不到指定的文件。":"SQLServerDAL"} System.Exception {System.IO.FileNot

代码

using System;
using System.Configuration;
using System.Collections.Generic;
using System.Text;
using IDAL;
using System.Reflection;

/// <summary>
/// DataAccess_Admin 的摘要说明
/// </summary>
namespace DALFactory
{
    public sealed class DataAccess_Admin
    {
        private static readonly string path = "SQLServerDAL";//ConfigurationManager.AppSettings["DAL"];//名称空间的名字

        private DataAccess_Admin() { }

        /// <summary>
        /// 创建对象或从缓存获取
        /// </summary>
        public static object CreateObject(string path, string CacheKey)
        {
            object objType = DataCache.GetCache(CacheKey);//从缓存读取
            if (objType == null)
            {
                try
                {
                    objType = Assembly.Load(path).CreateInstance(CacheKey);//反射创建
                    DataCache.SetCache(CacheKey, objType);// 写入缓存
                }
                catch(Exception e)
                { 
                    throw e;
                }
            }
            return objType;
        }

        public static IAdmin Createtb_Admin()
        {
            string CacheKey = path + ".TAdmin";
            return (IAdmin)CreateObject(path, CacheKey);//返回程序集指定的类实例
        }
    }
}




using System.Configuration;

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
/// <summary>
/// 缓存相关的操作类
/// </summary>
namespace DALFactory
{
    public class DataCache
    {
        /// <summary>
        /// 获取当前应用程序指定CacheKey的Cache值
        /// </summary>
        /// <param name="CacheKey"></param>
        /// <returns></returns>
        public static object GetCache(string CacheKey)
        {
            System.Web.Caching.Cache objCache = HttpRuntime.Cache;
            return objCache[CacheKey];
        }

        /// <summary>
        /// 设置当前应用程序指定CacheKey的Cache值
        /// </summary>
        /// <param name="CacheKey"></param>
        /// <param name="objObject"></param>
        public static void SetCache(string CacheKey, object objObject)
        {
            System.Web.Caching.Cache objCache = HttpRuntime.Cache;
            objCache.Insert(CacheKey, objObject);
        }
    }
}
--------------------编程问答-------------------- SQLServerDAL.TAdmin
这个路径你能找到吗 --------------------编程问答-------------------- SQLServerDAL 这是我数据访问层的名字空间
TAdmin 这个是类的名字 


应该可以找到啊 
--------------------编程问答-------------------- objType = Assembly.Load(path).CreateInstance(CacheKey);//反射创建 

path是程序集的名字吧,所以是需要SQLServerDAL 就行了,CreateInstance的时候填入类的名字 --------------------编程问答-------------------- 是这样的啊   --------------------编程问答--------------------
引用 3 楼 fuadam 的回复:
objType = Assembly.Load(path).CreateInstance(CacheKey);//反射创建 

path是程序集的名字吧,所以是需要SQLServerDAL 就行了,CreateInstance的时候填入类的名字


昨天没有仔细看,也没有仔细了解,呵呵。 --------------------编程问答-------------------- 你在启动项项目中,增加SQLServerDAL的引用 就行了
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,