无法在 MVC4 Web API 中加载文件或程序集“System.Net.Http,版本 = 2.0.0.0" [英] Could not load file or assembly 'System.Net.Http, Version=2.0.0.0 in MVC4 Web API

查看:39
本文介绍了无法在 MVC4 Web API 中加载文件或程序集“System.Net.Http,版本 = 2.0.0.0"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题.
我使用 MVC 4 和新的 Web API 开发了一个应用程序,它在本地运行良好.我在服务器上安装了 MVC4 并部署了应用程序.现在我收到以下错误:

I have a bit of a weird problem.
I developed an app with MVC 4 and the new Web API and it works fine locally. I installed MVC4 on the server and deployed the app. Now I get the following error:

无法加载文件或程序集System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(来自 HRESULT 的异常:0x80131040)

Could not load file or assembly 'System.Net.Http, 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)

描述:在执行当前 Web 请求的过程中发生了未处理的异常.请查看堆栈跟踪以获取有关错误及其来源的更多信息

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

有趣的是,我本地的包文件夹或 ASP.NET MVC 4Assemblies 文件夹中的 System.Net.Http 版本是 1.0.0.0.我实际上从我的项目中删除了对 System.Net.Http 的引用,但我仍然收到相同的消息.我对它从哪里获得 2.0.0.0 引用以及为什么它可以在本地工作而不是在服务器上工作感到有些困惑.

Funny enough, the version of System.Net.Http that I locally have either in my package folder or in the ASP.NET MVC 4Assemblies folder is 1.0.0.0. I actually removed the reference to System.Net.Http from my project, but I still get the same message. I'm a bit confused about where it gets the 2.0.0.0 reference from and why it would work locally but not on the server.

查看nuget依赖:

ASP.NET WEB API 核心库(测试版)依赖于 System.Net.Http.Formatting.
而 System.Net.Http.Formatting 依赖于 System.Net.Http.
我想这就是它的来源.但是我安装了这个包的2.0.20126.16343版本,只是里面的dll版本是1.0.0.0

ASP.NET WEb API Core Libraries (Beta) depends on System.Net.Http.Formatting.
And System.Net.Http.Formatting depends on System.Net.Http.
I guess that is where this comes from. But I do have Version 2.0.20126.16343 of this package installed, it's just that the dll inside has version 1.0.0.0

我错过了什么吗?

更新:

这是另一个 ASP.NET 应用程序的子应用程序,但另一个仍然基于 WebForms.所以,有些事情变得一团糟.但是,如果我在 web.config 中的程序集部分下进行清理,如果甚至找不到应用程序本身.

This is a sub-application of another ASP.NET app, but the other one is still based on WebForms. So, something is getting messed up. But if I do a clean under the assembly section in the web.config if does not even find the app itself anymore.

推荐答案

我在将应用程序部署到 appharbor 时遇到了同样的问题.尚不支持 .NET 4.5 的问题.我做了什么.

I had the same problem with deployment my app to appharbor. The problem it does not support .NET 4.5 yet. What I did.

  1. 将我的项目切换到 .NET 4.0 配置文件.
  2. 已卸载 Web API NuGet 包.
  3. 再次安装了 Web API(测试版)NuGet 包.
  4. 已验证 .csproj 文件包含所有引用的程序集,因此它将始终从 Bin 文件夹而不是 GAC 中获取.

这篇关于无法在 MVC4 Web API 中加载文件或程序集“System.Net.Http,版本 = 2.0.0.0"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆