System.Web.Http reference defaults to 4.0 version

2019-04-21 10:43发布

问题:

I am using the BreezeApi NuGet package in my project. It is in Visual Studio 2013.

I get this error.

Error 41 Assembly 'Breeze.WebApi2, Version=1.4.0.0, Culture=neutral, PublicKeyToken=f6085f1a45e2ac59' uses 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

I don't know why my project keeps referencing the 4.0 version. Things I tried:

  1. I removed the reference of system.web.http 4.0 from my project and browsed to the 5.0 DLL file location. As soon as I add it and come back to Solution Explorer, right click on the system.web.http dll, it is showing 4.0.0.0.

  2. I added assembly binding in web.config like below

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

How do I resolve this?

回答1:

This is what I did to solve an issue very similar to yours:

Error 2 Assembly 'Breeze.WebApi2, Version=1.4.0.0, Culture=neutral, PublicKeyToken=f6085f1a45e2ac59' uses 'System.Web.Http, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' c:\Repos\SPACodeCamper\packages\Breeze.Server.WebApi2.1.4.12\lib\Breeze.WebApi2.dll CC.Web

I got this error while doing the course Building Apps with Angular and Breeze - Part 1 by John Papa. It happened on step 3.15 after adding the Breeze Web API Controller to CC.Web.

To solve it we need to update the following NuGet Packages. I used NuGet Package Manager in Visual Studio 2013:

  1. Microsoft.AspNet.WebApi.Client from 5.0.0 to 5.1.2
  2. Microsoft.AspNet.WebApi.Core from 5.0.0 to 5.1.2
  3. Microsoft.AspNet.WebApi.WebHost from 5.0.0 to 5.1.2
  4. Microsoft.AspNet.WebApi.OData from 5.0.0 to 5.1.2 (this one I had to restart Visual Studio to complete the installation)

Updating the NuGet packages above will take care of bumping System.Web.Http's version to the correct one, in this case 5.1.0.0.



回答2:

I think your answer is given here.

You have to update the NuGet packages. The easiest one is update-package in the NuGet packet manager console.

Be aware of other dependencies that might break.



回答3:

I solved this by updating all my packages from NuGet.