c# - 无法更新到 Web API 2.1

标签 c# asp.net-web-api

我正在尝试将我的 Web API 从 2.0 更新到 2.1,但出现以下错误

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

在这条线上

GlobalConfiguration.Configure(WebApiConfig.Register);

在更新后运行 API 时在 global.asax.cs 中。

但这是正常的,因为它在csprog中引用了5.1.0

<Reference Include="System.Web.Http, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

我也尝试过命令行

Install-Package Microsoft.AspNet.WebApi -Version 5.1.0

我也有同样的问题,但有时它会给我一个错误,提示某些插件依赖于 Microsoft.AspNet.WebApi.core 5.0.0。

但我不明白为什么,因为插件的依赖项是 Microsoft.AspNet.WebApi.core >= 5.0.0. 所以 5.1.0 应该可以工作。

我尝试用

更新和忽略依赖
Install-Package -Ignoredependencies Microsoft.AspNet.WebApi -Version 5.1.0

我不再有错误,但 API 返回错误 500。

知道为什么对 Web API 2.1 的更新不起作用吗?

最佳答案

你有程序集绑定(bind)重定向吗?

<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.1.0.0" newVersion="5.1.0.0" />
           </dependentAssembly>
    </assemblyBinding>
</runtime>

关于c# - 无法更新到 Web API 2.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22213264/

相关文章:

c# - 用于密码哈希的 Rijndael 算法替代方案

c# - Qt creator - 如何启用对齐线?

asp.net-core - Swagger Swashbuckle 多态性不适用于接口(interface)类型

asp.net - 如何根据内部数组使用 OData 进行过滤?

asp.net - 如何从C#代码中调用网址

c# - 无效的 URI : The format of the URI could not be determined

c# - 通过反射将 Action<T> 传递给泛型方法?

jquery - ASP.net 中 Controller 和 API Controller 之间的区别?

c# - 从 PostMan 调用 asp.net 核心 web api

c# - Xamarin Forms - 如何为 Xamarin Forms 中的标签页编写单元测试?