我正在使用 .net 4.5 Web API 项目(项目 #1),但遇到了一个奇怪的错误。最初,所有内容都内置在一个项目中。我发现我想将业务逻辑(Project BLL)分解成一个单独的类库,以便可以在其他项目中重用它。我已经完成了将其拆分的过程,并发现它可以从 Project #2 中运行。当我尝试运行 Project #1 时,我遇到了一个奇怪的问题,当我尝试在 Project BLL 中调用一个函数时,我在 Application_Start 中得到一个 TypeLoadException。我在项目#2 中调用了同样的函数,没有问题。问题似乎只存在于项目#1 中,该项目在拆分前运行良好。我得到的确切错误消息是:
Could not load type 'Project.BLL.Mappers.v1.AutoMapperConfiguration' from assembly 'Project.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
在项目 #1 中,我可以使用 Intelesense 和 F12(转到定义)来查看这两个项目似乎连接正确。有什么想法吗?
更新: 这是整个堆栈跟踪。它没有命中 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