130

Just upgraded an ASP.NET MVC4 project to use Unity.WebApi version 5.0.0.0 and it requires System.Web.Http v 5.0.0.0 as per the following error:

Assembly 'Unity.WebApi, Version=5.1.0.0, Culture=neutral, PublicKeyToken=43da31bc42a85347' 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 am currently referencing System.Web.Http v4.0 but have the following NuGet packages upgraded to their respective latest versions:

  • ANTLRv3

  • Microsoft ASP.NET Universal Providers

  • Microsoft.Web.Infrastructure

  • Microsoft ASP.NET MVC

  • Microsoft ASP.NET Razor

  • Microsoft ASP.NET Universal Providers Core Libraries

  • Microsoft ASP.NET Universal Providers

  • Microsoft ASP.NET Web API 2 Client

  • Microsoft ASP.NET Web API 2 Core

  • Microsoft ASP.NET Web API 2 Web Host

  • Microsoft ASP.NET Web API 2

  • Microsoft ASP.NET Web Page

  • Microsoft.Web.Infrastructure

  • WebGrease

    via NuGet. I have not listed relevant JavaScript libraries such as Micrososft.jQuery.Unobtrusive Validation, etc.

What is the NuGet package to upgrade System.Web.Http or do I have to do this manually?

3
  • If you select "Include Prerelease" instead of "Stable" in the NuGet Package Manager, you'll see System.Web.Http. Is that what you're looking for?
    – William
    Nov 25, 2013 at 20:25
  • am I supposed to be searching for System.Web.Http after selecting "Include Prerelease"? Or where should I be looking?
    – Klaus Nji
    Nov 25, 2013 at 20:47
  • Disregard my above comment! That package is outdated. You should try to follow Stjin's suggestion below. Strangely enough, when I install Unity.WebApi in my MVC 4 project, it updates the System.Web.Http reference to v5.0 automatically, so I'm not sure why it isn't working for you. If all else fails, you could try uninstalling the Unity package and reinstalling it.
    – William
    Nov 25, 2013 at 21:16

2 Answers 2

215

You need the Microsoft.AspNet.WebApi.Core package.

You can see it in the .csproj file:

<Reference Include="System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.0.0\lib\net45\System.Web.Http.dll</HintPath>
</Reference>
5
  • I have Microsoft ASP.NET Web API 2 Core (id= Microsoft.AspNet.WebApi.Core ) upgraded to v5.0.0.0 as listed above. Looks like I need to remove and re-add them?
    – Klaus Nji
    Nov 25, 2013 at 21:46
  • 7
    Had to also clean, delete bin_deployableAssemblies and rebuild.
    – Klaus Nji
    Nov 25, 2013 at 21:54
  • Having almost the exact same project. Where is the bin_deployable Assemblies folder that everyone keeps talking about?
    – nzondlo
    Nov 26, 2013 at 21:17
  • @nzondlo I believe that folder is generated when Publishing an application. Not entirely sure though.
    – user247702
    Nov 26, 2013 at 21:25
  • 1
    @nzondlo bin_deployableAssemblies is just a regular folder, but it gets special treatment when it exists in your project's directory. Any .dll file in that folder is copied to the bin directory when you publish your web application. It was used to deploy the System.Web.Mvc dll (and others) with your web app before NuGet became mainstream. Jan 28, 2016 at 13:46
10

I have several projects in a solution. For some of the projects, I previously added the references manually. When I used NuGet to update the WebAPI package, those references were not updated automatically.

I found out that I can either manually update those reference so they point to the v5 DLL inside the Packages folder of my solution or do the following.

  1. Go to the "Manage NuGet Packages"
  2. Select the Installed Package "Microsoft ASP.NET Web API 2.1"
  3. Click Manage and check the projects that I manually added before.
3
  • Uninstalling the package and then immediatley reinstalling it fix it for me. Happened when bringing the project up on a different development machine. Automatic package restore got the wrong version somehow.
    – Matt J.
    Mar 6, 2014 at 22:41
  • 1
    Main problem is updating Web.Api for main project but referenced projects are still using older version of it. It should be update together via right clicking the Solution name and Manage Nuget Packages menu as @Tony mentioned. cheers!
    – Orhaan
    Jul 15, 2014 at 22:31
  • Install-Package Microsoft.AspNet.WebApi.Core
    – C Sharper
    May 21, 2018 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.