我正在尝试将我的 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/