最近学习petshop仿照工厂模式做了一个程序怎么都是找不到这个程序集
我也看了sqlserverdal这个属性了。确实和web.config的名称一样。现在我也不明白是什么问题了
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IO.FileNotFoundException: 未能加载文件或程序集“bjdream.SQLServerDAL”或它的某一个依赖项。系统找不到指定的文件。源错误: 
行 132:        {
行 133:            string className = path + ".webpicmanager";
行 134:            return (Iwebpicmanager)Assembly.Load(path).CreateInstance(className);
行 135:        }
行 136:        #endregion
 

解决方案 »

  1.   

    我想问的是我现在的程序集名称和<add key="WebDAL" value="SQLServerDAL"/>的这个value是一样的。但是仍然不能解决找不到文件的问题
      

  2.   

    “/Website”应用程序中的服务器错误。
    --------------------------------------------------------------------------------未能加载文件或程序集“SQLServerDAL.webpicmanager”或它的某一个依赖项。系统找不到指定的文件。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IO.FileNotFoundException: 未能加载文件或程序集“SQLServerDAL.webpicmanager”或它的某一个依赖项。系统找不到指定的文件。源错误: 
    行 132:        {
    行 133:            string className = path + ".webpicmanager";
    行 134:            return (Iwebpicmanager)Assembly.Load(path).CreateInstance(className);
    行 135:        }
    行 136:        #endregion
     源文件: C:\Documents and Settings\Administrator\桌面\Bjdream\DALFactory\DataAccess.cs    行: 134 程序集加载跟踪: 下列信息有助于确定程序集“SQLServerDAL.webpicmanager”无法加载的原因。
    警告: 程序集绑定日志记录被关闭。
    要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD)设置为 1。
    注意: 会有一些与程序集绑定失败日志记录关联的性能损失。
    要关闭此功能,请移除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。 堆栈跟踪: 
    [FileNotFoundException: 未能加载文件或程序集“SQLServerDAL.webpicmanager”或它的某一个依赖项。系统找不到指定的文件。]
       System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
       System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +50
       System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +211
       System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +141
       System.Reflection.Assembly.Load(String assemblyString) +25
       DALFactory.DataAccess.Createwebpicmanager() in C:\Documents and Settings\Administrator\桌面\Bjdream\DALFactory\DataAccess.cs:134
       BLL.webpicmanager..cctor() in C:\Documents and Settings\Administrator\桌面\Bjdream\BLL\webpicmanager.cs:18[TypeInitializationException: “BLL.webpicmanager”的类型初始值设定项引发异常。]
       BLL.webpicmanager..ctor() +0
       bjdream_manager_main_webadd_flash..ctor() in c:\Documents and Settings\Administrator\桌面\Bjdream\Website\bjdream_manager\main\webadd_flash.aspx.cs:18
       ASP.bjdream_manager_main_webadd_flash_aspx..ctor() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website\cc4a0e4e\2871a021\App_Web_ywqzqgl3.4.cs:0
       __ASP.FastObjectFactory_app_web_ywqzqgl3.Create_ASP_bjdream_manager_main_webadd_flash_aspx() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website\cc4a0e4e\2871a021\App_Web_ywqzqgl3.98.cs:0
       System.Web.Compilation.BuildResultCompiledType.CreateInstance() +58
       System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +113
       System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +32
       System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +62
       System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +294
       System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +147
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +152 
    --------------------------------------------------------------------------------
    版本信息: Microsoft .NET Framework 版本:2.0.50727.1882; ASP.NET 版本:2.0.50727.1879 
      

  3.   

    项目中添加对该程序集的引用
    类文件中添加对命名空间的引用:using .....
      

  4.   

    行 133: string className = path + ".webpicmanager";
    找不到这个文件吧
      

  5.   

    你程序集明明是bjdream.SQLServerDAL。
    你在web.config中
    <add key="WebDAL" value="SQLServerDAL"/>
    中却配置成SQLServerDAL;
    打开你生成的SQLServerDAL,如果生成的是SQLServerDAL.dll,则上面的配置就没错,如果是bjdream.SQLServerDAL,上面的配置就错了
      

  6.   

    是否添加DLL引用
    通过反射生成
       private static object GetInstance(string CacheKey)
            {
                object objType = DataCache.GetCache(CacheKey);
                if (objType == null)
                {
                    try
                    {
                        objType = Assembly.Load(DALFactory._path).CreateInstance(CacheKey);
                        DataCache.SetCache(CacheKey, objType);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                return objType;
            }
            public static IAnnounceDAL AnnounceDALInstance()
            {
                string CacheKey = DALFactory._path + ".AnnounceDAL";
                object objType = DALFactory.GetInstance(CacheKey);
                return (IAnnounceDAL)objType;
            }
      

  7.   

    我是上网找codesmith模板生成的代码。和petshop维一不同的是他用的是
    using Microsoft.Practices.EnterpriseLibrary.Data;
    using Microsoft.Practices.EnterpriseLibrary.Common;
    这个两个程序集去连接数据库
    我觉得是不是出在这个两个程序上面啊?
      

  8.   

    object objType = DataCache.GetCache(CacheKey);
    这个从缓存读取我没有用到啊
      

  9.   

    我详细的发下我的问题看看。希望大家能帮上忙
    我的是数据库连接用的是这个俩个程序集
    using Microsoft.Practices.EnterpriseLibrary.Data;
    using Microsoft.Practices.EnterpriseLibrary.Common;
    web.config配置是:
      <configSections>
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
      </configSections>
      <dataConfiguration   defaultDatabase= "SQLConnString "   />
      <appSettings>
        <add key="WebDAL" value="SQLServerDAL"/>
      </appSettings>
    SQLServerDAL的属性名称我已经核对过了。和这个value的值是一样的
    反射生成的方法:
            public static Iwebpicmanager Createwebpicmanager()
            {
                string className = path + ".webpicmanager";
                return (Iwebpicmanager)Assembly.Load(path).CreateInstance(className);
            }
    这是报的错误:
    System.IO.FileNotFoundException: 未能加载文件或程序集“SQLServerDAL”或它的某一个依赖项。系统找不到指定的文件
    跟踪信息如下:
    程序集加载跟踪: 下列信息有助于确定程序集“SQLServerDAL”无法加载的原因。
    警告: 程序集绑定日志记录被关闭。
    要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD)设置为 1。
    注意: 会有一些与程序集绑定失败日志记录关联的性能损失。
    要关闭此功能,请移除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。 堆栈跟踪: 
    [FileNotFoundException: 未能加载文件或程序集“SQLServerDAL”或它的某一个依赖项。系统找不到指定的文件。]
       System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
       System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +50
       System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +211
       System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +141
       System.Reflection.Assembly.Load(String assemblyString) +25
       DALFactory.DataAccess.Createwebpicmanager() in C:\Documents and Settings\Administrator\桌面\Bjdream\DALFactory\DataAccess.cs:134
       BLL.webpicmanager..cctor() in C:\Documents and Settings\Administrator\桌面\Bjdream\BLL\webpicmanager.cs:18[TypeInitializationException: “BLL.webpicmanager”的类型初始值设定项引发异常。]
       BLL.webpicmanager..ctor() +0
       bjdream_manager_main_webadd_flash..ctor() in c:\Documents and Settings\Administrator\桌面\Bjdream\Website\bjdream_manager\main\webadd_flash.aspx.cs:18
       ASP.bjdream_manager_main_webadd_flash_aspx..ctor() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website\cc4a0e4e\2871a021\App_Web_mkej10ro.24.cs:0
       __ASP.FastObjectFactory_app_web_mkej10ro.Create_ASP_bjdream_manager_main_webadd_flash_aspx() in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\website\cc4a0e4e\2871a021\App_Web_mkej10ro.98.cs:0
       System.Web.Compilation.BuildResultCompiledType.CreateInstance() +58
       System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +113
       System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +32
       System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +62
       System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +294
       System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +147
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +152 
    希望能解决问题
      

  10.   

    伤不起啊,难道是VS2010的BUG????
      

  11.   

    应该是在WEB的项目没有自动生成SQLServerDAL.DLL文件吧。如果没有这个DLL文件,反映会报错。
      

  12.   

    楼主注意了,你的这个问题是因为你的Web项目中没有引用SQLServerDAL,引用后就不会出问题了