C# 无法加载文件或程序集 System.Web.Mvc

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14694551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 12:42:03  来源:igfitidea点击:

Could not load file or assembly System.Web.Mvc

c#asp.netasp.net-mvcumbraco

提问by Said Roohullah Allem

I'm using umbraco 4.11.3 in my project.My project work well util that's on Windows 7 and run it from visual studio 2012. But it did not work in Win 8 when it run from visual studio 2012!

我在我的项目中使用 umbraco 4.11.3。我的项目在 Windows 7 上运行良好,并从 Visual Studio 2012 运行它。但是当它从 Visual Studio 2012 运行时,它在 Win 8 中不起作用!

Error is:

错误是:

Could not load file or assembly 'System.Web.Mvc, Version=2.0.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)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=2.0.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)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.

=== Pre-bind state information === LOG: User = Jahan-PC\jahan LOG: DisplayName = System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified) LOG: Appbase = file:///G:/20130204/SourceCode/Defraz.Movafaqiyat.WebApp/Defraz.Movafaqiyat.WebApp/ LOG: Initial PrivatePath = G:\20130204\SourceCode\Defraz.Movafaqiyat.WebApp\Defraz.Movafaqiyat.WebApp\bin Calling assembly : ClientDependency.Core.Mvc, Version=1.5.1.0, Culture=neutral, PublicKeyToken=null. === LOG: This bind starts in default load context. LOG: Using application configuration file: G:\20130204\SourceCode\Defraz.Movafaqiyat.WebApp\Defraz.Movafaqiyat.WebApp\web.config LOG: Using host configuration file: C:\Users\jahan\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Users/jahan/AppData/Local/Temp/Temporary ASP.NET Files/root/bc5b37d0/42db0b24/System.Web.Mvc.DLL. LOG: Attempting download of new URL file:///C:/Users/jahan/AppData/Local/Temp/Temporary ASP.NET Files/root/bc5b37d0/42db0b24/System.Web.Mvc/System.Web.Mvc.DLL. LOG: Attempting download of new URL file:///G:/20130204/SourceCode/Defraz.Movafaqiyat.WebApp/Defraz.Movafaqiyat.WebApp/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.

Stack Trace:

[FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=2.0.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)]
ClientDependency.Core.Mvc.MvcFilter.ValidateCurrentHandler() +0
ClientDependency.Core.Module.ClientDependencyModule.b__0(IFilter f) +31 System.Linq.Enumerable.Any(IEnumerable1 source, Func2 predicate) +146
ClientDependency.Core.Module.ClientDependencyModule.ValidateCurrentHandler(IEnumerable`1 filters) +127
ClientDependency.Core.Module.ClientDependencyModule.HandleRequest(Object sender, EventArgs e) +179
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

无法加载文件或程序集“System.Web.Mvc,版本=2.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)

说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

异常详细信息:System.IO.FileLoadException:无法加载文件或程序集“System.Web.Mvc,版本=2.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)

源错误:

执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常来源和位置的信息。

程序集加载跟踪:以下信息有助于确定无法加载程序集“System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”的原因。

=== 预绑定状态信息 === LOG: User = Jahan-PC\jahan LOG: DisplayName = System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified) LOG: Appbase = file:///G:/20130204/SourceCode/Defraz.Movafaqiyat.WebApp/Defraz.Movafaqiyat.WebApp/ LOG: Initial PrivatePath = G:\20130204\SourceCode\Defraz.Movafaqiyat.WebApp\Defraz.Movafaqiyat.WebApp\ bin 调用程序集:ClientDependency.Core.Mvc,版本=1.5.1.0,Culture=neutral,PublicKeyToken=null。=== LOG:此绑定在默认加载上下文中启动。日志:使用应用程序配置文件:G:\20130204\SourceCode\Defraz.Movafaqiyat.WebApp\Defraz.Movafaqiyat.WebApp\web.config 日志:使用主机配置文件:C:\Users\jahan\Documents\IISExpress\config\aspnet .config LOG:使用来自 C:\Windows\Microsoft 的机器配置文件。NET\Framework\v4.0.30319\config\machine.config。LOG:后政策参考:System.Web.Mvc,版本=2.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35 LOG:正在尝试下载新的 URL 文件:///C:/Users/jahan/AppData/Local/Temp /临时 ASP.NET 文件/root/bc5b37d0/42db0b24/System.Web.Mvc.DLL。日志:正在尝试下载新的 URL 文件:///C:/Users/jahan/AppData/Local/Temp/Temporary ASP.NET Files/root/bc5b37d0/42db0b24/System.Web.Mvc/System.Web.Mvc.DLL . 日志:正在尝试下载新的 URL 文件:///G:/20130204/SourceCode/Defraz.Movafaqiyat.WebApp/Defraz.Movafaqiyat.WebApp/bin/System.Web.Mvc.DLL。警告:比较程序集名称导致不匹配:主要版本 ERR:无法完成程序集设置 (hr = 0x80131040)。探测终止。Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Users/jahan/AppData/Local/Temp/Temporary ASP.NET Files/root/ bc5b37d0/42db0b24/System.Web.Mvc.DLL。日志:正在尝试下载新的 URL 文件:///C:/Users/jahan/AppData/Local/Temp/Temporary ASP.NET Files/root/bc5b37d0/42db0b24/System.Web.Mvc/System.Web.Mvc.DLL . 日志:正在尝试下载新的 URL 文件:///G:/20130204/SourceCode/Defraz.Movafaqiyat.WebApp/Defraz.Movafaqiyat.WebApp/bin/System.Web.Mvc.DLL。警告:比较程序集名称导致不匹配:主要版本 ERR:无法完成程序集设置 (hr = 0x80131040)。探测终止。Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Users/jahan/AppData/Local/Temp/Temporary ASP.NET Files/root/ bc5b37d0/42db0b24/System.Web.Mvc.DLL。日志:正在尝试下载新的 URL 文件:///C:/Users/jahan/AppData/Local/Temp/Temporary ASP.NET Files/root/bc5b37d0/42db0b24/System.Web.Mvc/System.Web.Mvc.DLL . 日志:正在尝试下载新的 URL 文件:///G:/20130204/SourceCode/Defraz.Movafaqiyat.WebApp/Defraz.Movafaqiyat.WebApp/bin/System.Web.Mvc.DLL。警告:比较程序集名称导致不匹配:主要版本 ERR:无法完成程序集设置 (hr = 0x80131040)。探测终止。/Users/jahan/AppData/Local/Temp/Temporary ASP.NET Files/root/bc5b37d0/42db0b24/System.Web.Mvc.DLL。日志:正在尝试下载新的 URL 文件:///C:/Users/jahan/AppData/Local/Temp/Temporary ASP.NET Files/root/bc5b37d0/42db0b24/System.Web.Mvc/System.Web.Mvc.DLL . 日志:正在尝试下载新的 URL 文件:///G:/20130204/SourceCode/Defraz.Movafaqiyat.WebApp/Defraz.Movafaqiyat.WebApp/bin/System.Web.Mvc.DLL。警告:比较程序集名称导致不匹配:主要版本 ERR:无法完成程序集设置 (hr = 0x80131040)。探测终止。/Users/jahan/AppData/Local/Temp/Temporary ASP.NET Files/root/bc5b37d0/42db0b24/System.Web.Mvc.DLL。日志:尝试下载新的 URL 文件:///C:/Users/jahan/AppData/Local/Temp/Temporary ASP.NET Files/root/bc5b37d0/42db0b24/System.Web.Mvc/System.Web.Mvc.DLL . 日志:正在尝试下载新的 URL 文件:///G:/20130204/SourceCode/Defraz.Movafaqiyat.WebApp/Defraz.Movafaqiyat.WebApp/bin/System.Web.Mvc.DLL。警告:比较程序集名称导致不匹配:主要版本 ERR:无法完成程序集设置 (hr = 0x80131040)。探测终止。/20130204/SourceCode/Defraz.Movafaqiyat.WebApp/Defraz.Movafaqiyat.WebApp/bin/System.Web.Mvc.DLL。警告:比较程序集名称导致不匹配:主要版本 ERR:无法完成程序集设置 (hr = 0x80131040)。探测终止。/20130204/SourceCode/Defraz.Movafaqiyat.WebApp/Defraz.Movafaqiyat.WebApp/bin/System.Web.Mvc.DLL。警告:比较程序集名称导致不匹配:主要版本 ERR:无法完成程序集设置 (hr = 0x80131040)。探测终止。

堆栈跟踪:

[FileLoadException:无法加载文件或程序集“System.Web.Mvc,版本=2.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。定位的程序集的清单定义与程序集引用不匹配。(来自 HRESULT 的异常:0x80131040)]
ClientDependency.Core.Mvc.MvcFilter.ValidateCurrentHandler() +0
ClientDependency.Core.Module.ClientDependencyModule.b__0(IFilter f) +31 System.Linq.Enumerable.Any( 1 source, Funcdienumerable) +146 pre
ClientDependency.Core.Module.ClientDependencyModule.ValidateCurrentHandler(IEnumerable`1 过滤器) +127
ClientDependency.Core.Module.ClientDependencyModule.HandleRequest(Object sender, EventArgs e) +179
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&completedSynchronously) +69

Note:published project on IIS works well in win7 and win8. My project isn't based on ASP.NET MVC. Please help me.

注意:在 IIS 上发布的项目在 win7 和 win8 下运行良好。我的项目不是基于 ASP.NET MVC。请帮我。

采纳答案by Lucent Fox

We're using Azure cloud to run a deployment and I got the same error. Since you can't really install packages onto the server instances, the way to solve this is to go into References for your project, find the reference to the library that it's complaining is missing, go into properties, then set Copy Local to True. Redeploy and you're all set.

我们正在使用 Azure 云来运行部署,但我遇到了同样的错误。由于您无法真正将软件包安装到服务器实例上,因此解决此问题的方法是进入您的项目的 References,找到它抱怨缺少的库的引用,进入属性,然后将 Copy Local 设置为 True。重新部署,一切就绪。

回答by Jonathan

I'm assuming this is a new machine, seeing as you have the new OS and different version of Visual Studio. I think you need to install MVC Framework version 2, as that's what your Umbraco install is expecting. You can either install the Framework, and get the DLLs into your GAC, or copy the DLLs from your good system to the bin folder of your web application.

我假设这是一台新机器,因为您拥有新的操作系统和不同版本的 Visual Studio。我认为您需要安装 MVC 框架版本 2,因为这是您的 Umbraco 安装所期望的。您可以安装框架,然后将 DLL 放入您的 GAC,或者将 DLL 从您的良好系统复制到您的 Web 应用程序的 bin 文件夹中。

Note, you're saying your project "doesn't use" MVC, but I think you'll find Umbraco does. The error, at any rate, is telling you that the system expects to find it.

请注意,您是说您的项目“不使用”MVC,但我认为您会发现 Umbraco 使用了。无论如何,该错误告诉您系统希望找到它。

回答by Digbyswift

Umbraco 4.11.3 doesn't use MVC2, it uses MVC3 so I would guess that you have a reference in your web.config to the MVC2 library, possibly in the compilation > assembliessection. It should look something like this:

Umbraco 4.11.3 不使用 MVC2,它使用 MVC3,所以我猜你在 web.config 中有一个对 MVC2 库的引用,可能在compilation > assemblies部分。它应该是这样的:

<compilation defaultLanguage="c#" batch="false" targetFramework="4.0" debug="true">
  <assemblies>
    <!-- ASP.NET 4.0 Assemblies -->
    <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
    <add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  </assemblies>
  <!-- Added in Umbraco 4.6.2 -->
  <buildProviders>
    <add extension=".cshtml" type="umbraco.MacroEngines.RazorBuildProvider, umbraco.MacroEngines" />
    <add extension=".vbhtml" type="umbraco.MacroEngines.RazorBuildProvider, umbraco.MacroEngines" />
    <add extension=".razor" type="umbraco.MacroEngines.RazorBuildProvider, umbraco.MacroEngines" />
  </buildProviders>
  <!-- End of added in Umbraco 4.6.2 -->
</compilation>

回答by Serj Sagan

The correct fix for this issue is to:

此问题的正确解决方法是:

  1. Right-click on Referencesin your Solution Explorerand choose Manage NuGet Packages
  2. On the left side select Updates
  3. In the middle section select Microsoft ASP.NET MVC
  4. You should see an Updatebutton appear in your selection, click on it
  1. 右键单击References您的Solution Explorer并选择Manage NuGet Packages
  2. 在左侧选择 Updates
  3. 在中间部分选择 Microsoft ASP.NET MVC
  4. 您应该会看到一个Update按钮出现在您的选择中,点击它

That's it...accept any T&Cs that might pop-up and either publish or run your project locally. If you're still having problems running your project locally, try closing Visual Studio deleting the .SUO file for the project and try opening the solution again...try running again.

就是这样......接受任何可能弹出的条款和条件,并在本地发布或运行您的项目。如果在本地运行项目时仍有问题,请尝试关闭 Visual Studio,删除项目的 .SUO 文件,然后再次尝试打开解决方案...尝试再次运行。