无法加载文件或程序集System.Web.Mvc或其依赖项之一

目前正在开发asp.net mvc5(旧的mvc3项目)。 它构建得很好,但是当我启动项目但是当我运行项目时,我面临以下错误。

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) 

不确定我怎么能解决这个问题,任何想法?

这是程序集加载跟踪:

 === Pre-bind state information === LOG: DisplayName = System.Web.Mvc (Partial) WRN: Partial binding information was supplied for an assembly: WRN: Assembly Name: System.Web.Mvc | Domain ID: 2 WRN: A partial bind occurs when only part of the assembly display name is provided. WRN: This might result in the binder loading an incorrect assembly. WRN: It is recommended to provide a fully specified textual identity for the assembly, WRN: that consists of the simple name, version, culture, and public key token. WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue. LOG: Appbase = file:///C:/Users/joaki/Source/Repos/2015-TimeAdministration/Source/V2/SalesWeb2/TimeReportV2/ LOG: Initial PrivatePath = C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\bin Calling assembly : (Unknown). === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\web.config LOG: Using host configuration file: C:\Users\joaki\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind). LOG: Attempting download of new URL file:///C:/Users/joaki/AppData/Local/Temp/Temporary ASP.NET Files/root/a90c5137/552c494a/System.Web.Mvc.DLL. LOG: Attempting download of new URL file:///C:/Users/joaki/AppData/Local/Temp/Temporary ASP.NET Files/root/a90c5137/552c494a/System.Web.Mvc/System.Web.Mvc.DLL. LOG: Attempting download of new URL file:///C:/Users/joaki/Source/Repos/2015-TimeAdministration/Source/V2/SalesWeb2/TimeReportV2/bin/System.Web.Mvc.DLL. LOG: Using application configuration file: C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\web.config LOG: Using host configuration file: C:\Users\joaki\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Redirect found in application configuration file: 4.0.0.1 redirected to 5.2.3.0. LOG: Post-policy reference: System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Users/joaki/AppData/Local/Temp/Temporary ASP.NET Files/root/a90c5137/552c494a/System.Web.Mvc.DLL. LOG: Attempting download of new URL file:///C:/Users/joaki/AppData/Local/Temp/Temporary ASP.NET Files/root/a90c5137/552c494a/System.Web.Mvc/System.Web.Mvc.DLL. LOG: Attempting download of new URL file:///C:/Users/joaki/Source/Repos/2015-TimeAdministration/Source/V2/SalesWeb2/TimeReportV2/bin/System.Web.Mvc.DLL. WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated. 

网络配置:

                                                                                          

如果您仔细阅读了您发布的融合日志,它会为您提供所需的信息。 我会把它剥离到重要的界限。

 LOG: Attempting download of new URL file:///C:/Users/joaki/Source/Repos/2015-TimeAdministration/Source/V2/SalesWeb2/TimeReportV2/bin/System.Web.Mvc.DLL. 

该应用程序正在寻找System.Web.Mvc.dll。 它已解析为您的Web应用程序的bin文件夹下的那个: C:\ Users \ joaki \ Source \ Repos \ 2015-TimeAdministration \ Source \ V2 \ SalesWeb2 \ TimeReportV2 \ bin \ System.Web.Mvc.DLL

接下来,它检查web.config中是否存在该DLL的任何程序集绑定重定向,并找到一个:

 LOG: Using application configuration file: C:\Users\joaki\Source\Repos\2015-TimeAdministration\Source\V2\SalesWeb2\TimeReportV2\web.config LOG: Redirect found in application configuration file: 4.0.0.1 redirected to 5.2.3.0. LOG: Post-policy reference: System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 

如果你查看你的web.config,会有这样的事情:

      

然后它检查在应用程序的bin目录中找到的System.Web.Mvc.dll是否是相同的版本:

 WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated. 

它抱怨主要版本不匹配。 这是4号版本中的第一个号码。 如果你回到日志中,那是因为bin文件夹中的System.Web.Mvc.dll实际上是版本4 .0.0.1,而不是所需的5 .2.3.0:

 LOG: Redirect found in application configuration file: 4.0.0.1 redirected to 5.2.3.0. 

您需要检查您的解决方案,以确保所有引用System.Web.Mvc的项目都在寻找相同的最新版本。 如果查看错误列表中的警告,您可能会发现有关此程序集的版本不匹配的警告。

更新参考

一种解决方案是右键单击Visual Studio中的解决方案,选择“管理解决方案的NuGet包…”并尝试更新项目以使用相同版本的System.Web.Mvc。

如果您事先清除bin文件夹,它也会有所帮助。

您还可以使用程序包管理器控制台来更新解决方案中的程序包:

 Update-Package Microsoft.AspNet.Mvc -version 5.2.3.0 

我不确定这是否会有所帮助。 但我也有这样的信息:

无法加载文件或程序集’System.Web.Mvc(1)’或其依赖项之一…

我真的不知道为什么,但当我检查Web应用程序的bin文件夹时,一些DLL文件有重复项,如“ System.Web.Mvc(1).dll ”等等。

我做的是,我删除了所有重复的文件(文件名上带有’(1)’或’(2)’…) ,然后重建Web应用程序然后再次工作。

你可以在这里发布你的web.config文件吗? 您似乎在较新的环境中打开了一个mvc3项目,并且您的IDE(即Visual Studio)的迁移function无法正常工作。 System.Web.Mvc.DLL的版本不匹配(在配置文件和bin /目录中的版本)。 有两种方法可以解决此问题:1。在配置文件中修改System.Web.Mvc软件包/程序集的版本。 2.将System.Web.Mvc.dll从旧项目复制到新项目(bin /文件夹)。

我之前遇到过其他.dll文件的类似问题。 那时,我选择删除所有.dll文件,并使用NuGet Package Manager再次下载它们。