日期:2014-05-17  浏览次数:20403 次

C# 三层结构的 工厂模式的报错的 小问题
大侠们,这个总是报: 调用的目标发生了异常。 相信很多都遇到过这个问题,
我在网上也找了很久没看到什么解决的办法。

其报错的部分为: return (IYYMLoginDao)Assembly.Load(path).CreateInstance(className);

在方法里面:
public static IYYMLoginDao CreateYYMLoginDao()
  {
  string className = path + ".YYMLoginDao";
  return (IYYMLoginDao)Assembly.Load(path).CreateInstance(className);
  }

using 这些都导到里面去了的。

这个也写好了的。
  private static readonly string path = ConfigurationManager.AppSettings["ServiceDAL"];

web.config 里面也配了的
 <appSettings>
  <add key="ServiceDAL" value="YYMAspNet_DAL"/>
 </appSettings>

就是 不明白怎么还有这个错。。。

求大侠解决。、

在网页里面的错误可以看到:

未能加载文件或程序集“YYMAspNet_DB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。系统找不到指定的文件。 

==============================================================================================
具体如下:

源错误: 


行 13: public class YYMLoginDao:IYYMLoginDao
行 14: {
行 15: private IDBHelper helper = DBHelper.GetInstance();
行 16: 
行 17: 
 

源文件: C:\Users\yongmao\Documents\Visual Studio 2010\Projects\YYMAspNetWeb\YYMAspNet_DAL\YYMLoginDao.cs 行: 15 

程序集加载跟踪: 下列信息有助于确定程序集“YYMAspNet_DB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”未能加载的原因。


警告: 程序集绑定日志记录被关闭。
要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD)设置为 1。
注意: 会有一些与程序集绑定失败日志记录关联的性能损失。
要关闭此功能,请移除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。

 

堆栈跟踪: 


[FileNotFoundException: 未能加载文件或程序集“YYMAspNet_DB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。系统找不到指定的文件。]
  YYMAspNet_DAL.YYMLoginDao..ctor() in C:\Users\yongmao\Documents\Visual Studio 2010\Projects\YYMAspNetWeb\YYMAspNet_DAL\YYMLoginDao.cs:15

[TargetInvocationException: 调用的目标发生了异常。]
  System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
  System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +98
  System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
  System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
  System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +1136
  System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +111
  System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) +62
  System.Reflection.Assembly.CreateInstance(String typeName) +22
  YYMAspNet_DALFactory.DataAccess.CreateYYMLoginDao() in C:\Users\yongmao\Documents\Visual Studio 2010\Projects\YYMAspNetWeb\YYMAspNet_DALFactory\YYMLoginDaoFactory.cs:15
  YYMAspNet_BLL.YYMLoginBll..ctor() in C:\Users\yongmao\Documents\Visual Studio 2010\Projects\YYMAspNetWeb\YYMAspNet_BLL\YYMLoginBll.cs:12
  YYMAspNetWeb.Login..ctor() in C:\Users\yongmao\Documents\Visual Studio 2010\Projects\YYMAspNetWeb\YYMAspNetWeb\Login.aspx.cs:13
  ASP.login_aspx..ctor() in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\8bfdeb29\c1c9e087\App_Web_thk0iqz2.0.cs:0