C# 无法加载文件或程序集';System.Web.Http,版本=5.2.2.0

C# 无法加载文件或程序集';System.Web.Http,版本=5.2.2.0,c#,odata,C#,Odata,我在API中添加了Odata v4包,我注意到它将我的Microsoft.AspNet.WebApi包更新为5.2.3版本。但是当我尝试使用 我的网站中的odata builder配置将其配置为显示以下错误 无法加载文件或程序集'System.Web.Http,版本=5.2.2.0' 我在我的项目中搜索了这个版本(5.2.2),但是每个东西都是5.2.3,我也更新了所有的包来解决这个问题,但是失败了。 对于System.Web.Http dll,“复制到本地”属性也是真的。 有什么想法吗?Vis

我在API中添加了Odata v4包,我注意到它将我的Microsoft.AspNet.WebApi包更新为5.2.3版本。但是当我尝试使用

我的网站中的odata builder配置将其配置为显示以下错误 无法加载文件或程序集'System.Web.Http,版本=5.2.2.0'

我在我的项目中搜索了这个版本(5.2.2),但是每个东西都是5.2.3,我也更新了所有的包来解决这个问题,但是失败了。 对于System.Web.Http dll,“复制到本地”属性也是真的。

有什么想法吗?

Visual studio为我解决了这个问题。版本冲突显示为警告,当我单击它时,会自动将绑定重定向添加到我的web配置中

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

<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>

这不是“真正的”解决方案,而是一种变通方法: 我已更改machine.config并将
替换为

  <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>


所以我可以工作,但如果您有其他网站正在运行…

请检查您的web.config。可能仍然有一个程序集重定向,将所有引用重定向到版本5.2.2.0。谢谢,我在web.config中找不到任何内容,当我添加config.MapODataServiceRoute(“odata”,null,GetEdmModel(),新的DefaultODataBatchHandler(GlobalConfiguration.DefaultServer))时,会发生此错误;在webApiconfigI中,你也遇到了同样的问题,你有没有找到解决办法?@Oberheim:我更新了我的答案,可能会对你有所帮助。这里也有同样的问题。有什么解决方案吗?我在web.config中也有,但我仍然得到:“无法加载文件或程序集'System.web.Http,Version=5.2.2.0”
  <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>