8

I have a problem with nuget package manager in vs 2015. Some packages like Unity has been installed with no problem. Some packages like EF had problems while installing. Some packages like Automapper had the same problem but when I installed another version of this package, It installed fine.

here is the output:

System.NullReferenceException: Object reference not set to an instance of an object. at NuGet.Protocol.Core.v3.GlobalPackagesFolderUtility.<AddPackageAsync>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at NuGet.Protocol.Core.v3.DownloadResourceV3.<GetDownloadResourceResultAsync>d__4.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NuGet.PackageManagement.PackageDownloader.<GetDownloadResourceResultAsync>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at NuGet.PackageManagement.NuGetPackageManager.<ExecuteNuGetProjectActionsAsync>d__42.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at NuGet.PackageManagement.NuGetPackageManager.<ExecuteNuGetProjectActionsAsync>d__42.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NuGet.PackageManagement.UI.UIActionEngine.<ExecuteActionsAsync>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NuGet.PackageManagement.UI.UIActionEngine.<PerformActionAsync>d__3.MoveNext() ========== Finished ========== 
4
  • Please be more descriptive Commented Oct 21, 2015 at 21:20
  • I try to say it breifly. but what description I should tell? Commented Oct 21, 2015 at 21:21
  • Give more information about what the problem is, what type of project do you have etc Commented Oct 21, 2015 at 21:24
  • 1
    The problem is nuget doesn't work correctly. Sometimes there is no problem with some packages, sometimes it has problem with some packages to install, but there is no reason!!! the only error is what I told above. But I think this isn't a problem of vs or project type, becuase I had the same problem with nuget console outside of vs. Commented Oct 21, 2015 at 21:27

5 Answers 5

20

It is a common problem with the use of the new protocol (version 3) nuget used in Visual Studio 2015. It is with multiple nuget packages, for example Microsoft.Owin 3.0.1. To fix this go to:

C:\Users\<your user name>\AppData\Roaming\NuGet 

And edit the XML configuration file, commenting the line of protocol 3:

<!-- add key = "nuget.org" value = "https://api.nuget.org/v3/index.json" protocolVersion = "3" /--> <add key = "nuget.org" value = "https://www.nuget.org/api/v2/" /> 

Maintenance settings for version 2. Save and restart visual studio 2015. You should now restore the nuget packages without problems.

Sign up to request clarification or add additional context in comments.

Comments

20

Same problem still exists in Visual Studio 2022. The solution:

  1. Navigate to C:\Users<your user name>\AppData\Roaming\NuGet // remember AppData is a hidden folder, so you will have to make Windows show hidden files and folders before you can see it
  2. Open NuGet.Config in Notepad (or whatever will let you edit it)
  3. In the "packageSources" section, look for the line:

add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3"

and delete 'protocolVersion="3"'

  1. Save the file and restart Visual Studio 2022

2 Comments

Excellent, thanks @Will. I'm so used to NuGet running smoothly that it's a shock when something like this happens.
Thanks. Also, right after fixing this issue with this solution, I fell into another issue around package sources, which got fixed with this stackoverflow.com/a/55483821/8326848.
2

When i've had Nuget problems in the past these are the steps i've done:

1) Use Nuget package manager to remove out of project(s)

2) Clean and Build (you'll have errors because you do longer have the references 2) Make sure the packages were removed from your packages.config (if not, delete and repeat step 2)

3) Make sure the .dlls were removed from your bin folder (if not, delete and repeat step 2)

4) Add packages back in and rebuild. Ensure the packages were added to packages.config (with appropriate version) and .dlls were added back to the bin folder (with appropriate version).

2 Comments

The problem is I never installed them, there is no packages.config and there is no another assembly of the package!! I have 7 project in my solution and diffrent packages in each of them.
The avoid the problem 4), you can use Project Dependency Browser (projectdependencybrowser.org) which can analyze a C# project for NuGet/DLL referencing problems...
1
  1. My problem happens in NuGet.Config (he NuGet.Config file path: C:\Users\<UserName>\AppData\Roaming\NuGet)

  2. Reason:Tools -> NuGet Package Manager -> Package Management Settings -> Package Source ->

    nuget.org=https://api.nuget.org/v3/index.json 

    The default package source has attribute protocolVersion="3",but I modified it to my offline package source, meanwhile creating a new package source:

    nuget.ort=https://api.nuget.org/v3/index.json 

    The new package source has no attribute protocolVersion="3",so I always fail to install packages whether of online or offline.

  3. Solution: Add ProtocolVersion="3" to

    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3"/> 

    and remove ProtocolVersion="3" in my offline package source.

Comments

0

I am running VS 2017, but was having this error with the TFS build server during the "dotnet restore" task. The issue was we had an internal local file share, but the nuget.config had protocolVersion="3" for that entry. After removing that property, the build was successful.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.