Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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], 
InvalidOperationException
+ FullyQualifiedErrorId :     
NuGetMissingPackages, 
NuGet.PackageManagement.PowerShellCmdlets.UpdatePackageCommand

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=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.Formatting.dll</HintPath>
</Reference>

...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 4.1.1.2 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=5.2.6.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)'

Where is it getting this version 5.2.6.0 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.

like image 331
Darren Avatar asked Jul 20 '18 00:07

Darren


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.

like image 197
Darren Avatar answered Oct 21 '22 15:10

Darren


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.

like image 38
TPG Avatar answered Oct 21 '22 14:10

TPG