无法加载文件或程序集“System.Web.Http, Version=5.2.2.0”

11

我在API中添加了Odata v4 package,我注意到它将我的Microsoft.AspNet.WebApi包更新到5.2.3版本。但是当我尝试在我的WebApiConfig中使用odata builder configuation时,出现错误信息:'Could not load file or assembly 'System.Web.Http, Version=5.2.2.0'

config.MapODataServiceRoute("odata", null, GetEdmModel(), new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));

在我的项目中,我搜索了这个版本(5.2.2),但是一切都是5.2.3,我也更新了所有的包来解决这个问题,但是失败了。同时System.Web.Http dll的“Copy to Local”属性也是true。有什么想法吗?


2
检查您的 web.config 文件。可能仍然存在一个程序集重定向,将所有引用重定向到版本 5.2.2.0。 - HaukurHaf
谢谢,我在web.config文件中没有发现任何东西,当我将以下代码config.MapODataServiceRoute("odata", null, GetEdmModel(), new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));添加到webApiconfig文件时出现了这个错误。 - Linoy
我有完全相同的问题,你找到解决方案了吗? - Oberheim
@Oberheim:我更新了我的回答,也许那会对你有所帮助。 - Linoy
这里也有同样的问题。有解决方案吗? - Yann Olaf
2个回答

13

Visual Studio解决了我的问题。版本冲突显示为警告,并且当我单击时,它会自动将绑定重定向添加到我的Web配置文件中。

https://msdn.microsoft.com/en-us/library/2fc472t2.aspx

解决我的问题的绑定重定向是:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31BF3856AD364E35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31BF3856AD364E35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
</assemblyBinding>

我也在web.config中有这个,但我仍然得到了:“无法加载文件或程序集'System.Web.Http,版本=5.2.2.0” - JonathanPeel

0

这不是一个“真正”的解决方案,而是一个变通方法: 我已经更改了machine.config并用以下内容替换了<runtime />

  <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
        </dependentAssembly>
      </assemblyBinding>
    </runtime>

所以它可以工作,但如果您有其他网站在运行...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接