大侠们,这个总是报: 调用的目标发生了异常。 相信很多都遇到过这个问题,
我在网上也找了很久没看到什么解决的办法。其报错的部分为: 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
__ASP.FastObjectFactory_app_web_thk0iqz2.Create_ASP_login_aspx() in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\8bfdeb29\c1c9e087\App_Web_thk0iqz2.1.cs:0
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +109
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +31
System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +167
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +128
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
我在网上也找了很久没看到什么解决的办法。其报错的部分为: 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
__ASP.FastObjectFactory_app_web_thk0iqz2.Create_ASP_login_aspx() in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\8bfdeb29\c1c9e087\App_Web_thk0iqz2.1.cs:0
System.Web.Compilation.BuildResultCompiledType.CreateInstance() +32
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp) +109
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +31
System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +167
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +128
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
主要是你生成的dll名称,项目属性里是否有更改<add key="ServiceDAL" value="YYMAspNet_DAL"/> 配置是否正确
你确信这个配置是正确的吗?
配置是正确的。
引用我不太清楚是否添加了。不过在我的DAL 层里面引用有 IDAL , DB层,model实体层。
如果还要添加引用 是添加哪一个引用呢?我按照你说的“DAL项目的编译输出是指向的网站的bin目录而不是它自己的bin目录。”
将编译输出指向网站的bin目录,就没报错了。可以运行出来了。