无法加载文件或程序集'System.Web.Mvc'或者它的一个相关项.2项目.一次只有一个能起作用

本文关键字:一个 起作用 有一个 2项目 一次 程序集 文件 加载 System Web 或者 | 更新日期: 2023-09-27 18:08:33

所以我有2个网站项目(在许多其他测试/dll项目)在我的解决方案。

项目A - CMS -标准Web项目(与一些Web API集成)项目B -展示站点- MVC 5.

我构建项目A并运行它。它可以工作,没有意外的bug。然后我构建项目B。项目B正常工作,同样没有意外的错误。

我回去查看项目A上的一些东西,在运行时我得到以下错误:

无法加载文件或程序集"System.Web"。Mvc’或它的一个依赖项。定位的程序集的清单定义与程序集引用不匹配。(Exception from HRESULT: 0x80131040)

Description:当前web请求执行过程中发生未处理的异常。请查看堆栈跟踪以获得有关错误及其在代码中的起源位置的更多信息。

异常详细信息: System.IO.FileLoadException: Could not load file or assembly 'System.Web。Mvc’或它的一个依赖项。定位的程序集的清单定义与程序集引用不匹配。(Exception from HRESULT: 0x80131040)

[FileLoadException: Could not load file or assembly 'System.Web.Mvc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
[FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +16
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
[ConfigurationErrorsException: Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +285
System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516
[HttpException (0x80004005): Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9915300
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

然后我必须构建项目A以使其在运行时加载。但是项目B也有同样的问题。

我已经进入项目的/bin/文件夹,并观察到一些奇怪的事情。假设我正在查看项目A的/bin

如果我构建项目A, System.Web.Mvc.dll文件的版本为5.1.20129.0如果我构建项目B,相同的DLL文件会将其版本向后更改一步。5.0.11001.0

使用这个信息,我可以理解为什么错误被触发,因为它认为它是一个更高的版本比那里的版本。

并且,它不能与我们的Git仓库同步,因为没有其他开发人员遇到这个问题。

有人知道这是怎么发生的吗?还有我该怎么补救?

Ta

无法加载文件或程序集'System.Web.Mvc'或者它的一个相关项.2项目.一次只有一个能起作用

右键单击解决方案,进入公共属性下的启动项目,选择多个启动项目,选择两个项目。这将运行两个项目并解决您的问题

相关文章: