28

I am trying to add Microsoft.AspNet.WebApi Nuget Package to a C# Class Library Project. Here's the Project source code in case you need it.

When I execute the following command in the Nuget Package Manager Console in Visual Studio 2013 (it has latest .NET 4.5 in it)

PM> install-package Microsoft.AspNet.WebApi ErrandBoy.Web.Common

I get the following Error.

PM> install-package Microsoft.AspNet.WebApi ErrandBoy.Web.Common
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.WebHost (≥ 5.2.2 && < 5.3.0)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Core (≥ 5.2.2 && < 5.3.0)'.
Attempting to resolve dependency 'Microsoft.AspNet.WebApi.Client (≥ 5.2.2)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 6.0.4)'.
'Microsoft.AspNet.WebApi 5.2.2' already installed.
Adding 'Newtonsoft.Json 6.0.4' to ErrandBoy.Web.Common.
Successfully added 'Newtonsoft.Json 6.0.4' to ErrandBoy.Web.Common.
Adding 'Microsoft.AspNet.WebApi.Client 5.2.2' to ErrandBoy.Web.Common.
install-package : Failed to add reference to 'System.Net.Http'. Please make sure that it is in the Global Assembly Cache.
At line:1 char:1
+ install-package Microsoft.AspNet.WebApi ErrandBoy.Web.Common
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

The specific error line is the following. It seems to be where it's trying to add reference to Adding 'Microsoft.AspNet.WebApi.Client 5.2.2'

Failed to add reference to 'System.Net.Http'. Please make sure that it is 
in the Global Assembly Cache.

I've never gotten such an error before. I did see a similar error on this SO Overflow question => Error on installing ASP.NET Identity 2 Samples but that one has no answer.

Error Screenshot:

https://github.com/theShiva/ErrandBoy failed to add reference to system.net.http nuget package web api error

Community
  • 1
  • 1
Shiva
  • 20,575
  • 14
  • 82
  • 112
  • Do you have the required .NET version installed? – itsme86 Dec 26 '14 at 00:43
  • Yes. It's on a Windows 8.1 ENT VM with VS 2013 and all .Net versions until 4.5 – Shiva Dec 26 '14 at 01:29
  • What is target framework for your classlibrary ? – dotnetstep Dec 26 '14 at 01:32
  • `.Net Framework 4.5` – Shiva Dec 26 '14 at 01:34
  • 4
    Looking at the NuGet source code the underlying exception is added as an InnerException to another one so the actual error message is not shown. You should be able to get the underlying error by running something like `$error[0].Exception.ToString()` in the Package Manager Console. – Matt Ward Dec 26 '14 at 11:00
  • 1
    Had the same problem but I ran the install-package command a couple of times (with different error messages) and finally it installed correctly. The underlying error was The data necessary to complete this operation is not yet available. (Exception from HRESULT: 0x8000000A) – Dan Feb 09 '15 at 15:33

4 Answers4

26

I just had the same issue. I solved it by manually adding System.Net.Http to the references. Then it complained about others, but after adding them manually one by one I was able to install the package with NuGet.

Adam Szabo
  • 11,302
  • 18
  • 64
  • 100
8

I had the same issue. I simply closed my visual studio, and started it up again. Thereafter the package installed without any errors.

Daniel PP Cabral
  • 1,604
  • 1
  • 13
  • 19
2

I solved it just by changing .Net framework version to 4.6.1 in the project settings. And then I`ve installed everything succesfully.

didushyn
  • 21
  • 1
0

Did the installation from package manager console and it did the trick.

PAVITRA
  • 761
  • 2
  • 12
  • 24