Can't load Assembly System.Net.Http.Formatting in .Net Solution


I get the following error when trying to update-package on the NuGet Console:

At line:1 char:1
+ Update-Package Microsoft.AspNet.WebApi -reinstall
+ CategoryInfo          : InvalidOperation: (:) [Update-Package], 
+ FullyQualifiedErrorId :     

When I try to install NuGet.PackageManagement.PowerShellCmdlets I get the error:

An error occured while trying to restore packages:Unable to find version '5.2.3' of package 'System.Net.Http.Formatting'.

In the .csproj file the version is 5.2.3 for System.Net.Http.Formatting

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

...and in the packages.config file the version is 5.2.3 for the package System.Net.Http.Formatting:

<package id="System.Net.Http.Formatting" version="5.2.3" targetFramework="net461"/>

In the properties of references the version is and the runtime version is v4.0.30319 for System.Net.Http.Formatting.

So my problem is that I cannot reinstall System.Net.Http.Formatting because it is now part of Microsoft.AspNet.WebApi apparently and when I try to install it I get the original error. I am going around in circles. If I just run the project as it is it compiles and I get the runtime error:

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

Where is it getting this version from? And if it is a dependency that is the problem I need to reinstall but I can't.

I am very inexperienced with packages and NuGet. All these problems arose when a coworker updated a few packages and put these changes in git but my project did not compile.

asked on Stack Overflow Jul 20, 2018 by Darren • edited Apr 9, 2019 by David Ferenczy Rogožan

2 Answers


This is how I solved the problem. I deleted the DLL System.Net.Http.Formatting. I made sure it was deleted from the .csproj file and the packages.config file.

Then I uninstalled the packages Microsoft.AspNet.WebApi.WebHost, Microsoft.AspNet.WebApi.Core and Microsoft.AspNet.WebApi.Client using NuGet.

Then I reinstalled the packages using NuGet, but I did not reinstall the System.Net.Http.Formatting package.

The dependent code in that originally required it is now in part of Microsoft.AspNet.WebApi.Client. It installed the System.Net.Http.Formatting package and the version 5.2.6 which my Solution was originally looking for and complaining about when it could not find it.

answered on Stack Overflow Jul 20, 2018 by Darren • edited Apr 9, 2019 by David Ferenczy Rogožan

I just need to update my Microsoft.AspNet.WebApi.Client within the NuGet to latest version 5.2.7 and the System.Net.Http.Formatting gets updated too.

Clean your project and rebuild.

answered on Stack Overflow Jan 19, 2021 by TPG

User contributions licensed under CC BY-SA 3.0