首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >无法加载文件或程序集System.Net.Http,带有ASP.NET (MVC 4) Web API OData预发行版的Version=4.0.0.0

无法加载文件或程序集System.Net.Http,带有ASP.NET (MVC 4) Web API OData预发行版的Version=4.0.0.0
EN

Stack Overflow用户
提问于 2013-09-24 21:14:38
回答 13查看 158.7K关注 0票数 81

问题

安装Microsoft package 5.0.0-rc1预发行版后,我遇到以下异常:

无法加载文件或程序集“System.Web.Http,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(HRESULT异常: 0x80131040)

我的MVC4项目是全新的,非常小,没有什么花哨的东西。I目标是.NET Framework4.5

我需要这个到implement PATCH using the Delta classnuget package (当我使用4.0.0.0版本的包时,Delta类不工作)。

我怎么才能修复它呢?

我的System.Web.Http版本

GAC中,我有version 5.0.0.0 of System.Web.Http

gacutil -l System.Web.Http全局程序集缓存包含以下程序集: System.Web.Http、Version=5.0.0.0、Culture=neutral、PublicKeyToken=31bf3856ad364e35、processorArchitecture=MSIL

Visual Studio中,当我浏览程序集时,给定的System.Web.Http版本是4.0.0.0 (为什么?)

在我的项目中,对System.Web.Http的引用

  • 的版本为CopyLocal=true

  • 软件包的\lib\net45\文件夹

我试过的东西

我尝试在Web.config中将重定向版本4.0.0.0绑定到5.0.0.0

<dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="4.0.0.0-4.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>

但它给了我另一个例外:

方法'System.Web.Http.GlobalConfiguration..cctor()‘访问字段'System.Web.Http.GlobalConfiguration.CS$<>9__CachedAnonymousMethodDelegate2’的

尝试失败。

我想4.0.0.0版本确实需要被核心Web Api引擎使用。

链接的问题

Code Analysis error Could not load file or assembly 'System.Net.Http, Version=2.0.0.0 in MVC4 Web API Could not load file or assembly 'System.Net.Http, Version=2.0.0.0 in MVC4 Web API

EN

回答 13

Stack Overflow用户

回答已采纳

发布于 2013-11-01 00:56:21

Visual Studio 2013有一个新功能来解决这个问题。在生成应用程序时,您应该会看到有关被引用的程序集的不同版本的警告。双击警告以将程序集绑定重定向添加到web.config。

有关更多详细信息,请参阅http://msdn.microsoft.com/en-us/library/2fc472t2.aspx

jeff.eynon在下面指出,您需要签出web.config (如果使用TFS源代码控制),以便让VS自动编辑该文件。谢谢你告诉我!

票数 164
EN

Stack Overflow用户

发布于 2013-09-24 23:09:58

我使用nuget将WebApi包升级到预发布版本,从而使其正常工作:

PM> Microsoft.AspNet.WebApi -Pre

为了强制项目使用最新版本的WebApi,需要对根Web.config进行一些修改:

1)网页版本2.0.0.0至3.0.0.0

<appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
</appSettings>

2) System.Web.Http和System.Net.Http.Formatting绑定重定向到5.0.0.0

<dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
    <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>

我想就是这样了

PS:高度受WebAPI OData 5.0 Beta - Accessing GlobalConfiguration throws Security Error启发的解决方案

票数 39
EN

Stack Overflow用户

发布于 2013-10-24 00:08:02

当我试图从项目模板更新一个热毛巾项目时,以及当我创建一个空项目并在VS 2012中通过nuget安装HotTowel时,我遇到了这个问题。

为了修复这个问题,我通过Nuget将Web Api Web Host和Web API包更新到了5.0,这是目前NuGet的最新版本(2013年10月23日)。

然后我添加了绑定指令:

<dependentAssembly>
  <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
  <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18982682

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档