我正在使用.net 4.5 Web API项目(项目#1),我收到了一个奇怪的错误。最初一切都建在一个项目中。我发现我想将业务逻辑(Project BLL)分解为一个单独的类库,以便可以在其他项目中重用它。我已经完成了将它拆开的过程,并发现它可以从Project#2开始工作。当我尝试运行Project#1时,我有一个奇怪的问题,当我尝试在Project BLL中调用一个函数时,我在Application_Start中得到一个TypeLoadException。我在Project#2中调用了同样的功能而没有任何问题。问题似乎只出现在项目#1中,在拆分之前工作正常。我得到的确切错误信息是:
Could not load type 'Project.BLL.Mappers.v1.AutoMapperConfiguration' from assembly 'Project.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
在Project#1中,我可以使用Intelesense和F12(Go To Definition)来查看这两个项目是否正确连接。有什么想法吗?
更新 这是整个堆栈跟踪。它没有遇到Global.asax.cs中的断点,所以我无法真正达到内部异常:
[TypeLoadException: Could not load type 'Project.BLL.Mappers.v1.AutoMapperConfiguration' from assembly 'Project.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.]
Project.BLL.WebApiApplication.Application_Start() in d:\Solutions\Project_1\Global.asax.cs:58
[HttpException (0x80004005): Could not load type 'Project.BLL.Mappers.v1.AutoMapperConfiguration' from assembly 'Project.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12864365
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475
[HttpException (0x80004005): Could not load type 'Project.BLL.Mappers.v1.AutoMapperConfiguration' from assembly 'Project.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12881108
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12722297
答案 0 :(得分:0)
检查项目配置并确保两个项目都针对相同的框架和平台(例如,任何Cpu)