50

I want to install Microsoft ASP.NET Identity Core through the use of Manage Nuget Packages, but when I click the install button the following error occurs:

The underlying connection was closed: An unexpected error occurred on a send

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
Mohsen
  • 772
  • 1
  • 7
  • 15

9 Answers9

108

Try pasting the following into a .reg file and run it. Then try running your NuGet command (no reboot required).

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319]
"SchUseStrongCrypto"=dword:00000001

Ran into this issue because TLS1.2 was not enabled (similar to Tony's response). Using http does not fix the situation because NuGet redirects to https now that TLS1.2 is enforced.

neoscribe
  • 2,203
  • 1
  • 21
  • 18
18

This is SSL cert issue on http://go.microsoft.com. Change the package source url to http://packages.nuget.org/v1/FeedService.svc/ which works for me.

Source: https://github.com/nuget/home

Jeff Mergler
  • 1,384
  • 20
  • 27
Ali Gol Gol
  • 775
  • 7
  • 14
15

I got this error on an old customer developer VM with Microsoft Visual Studio Premium 2012:

Install-Package : An error occurred while loading packages from 'https://nuget.org/api/v2/': The underlying connection was closed: An unexpected error occurred on a send

enter image description here

Solved it by going to Tools -> Extensions and Updates... -> Updates -> Visual Studio Gallery and Updated NuGet Package Manager from there.

enter image description here

After reboot everything worked:

enter image description here

Ogglas
  • 62,132
  • 37
  • 328
  • 418
  • 2
    This is the answer that solved it for me. Updating a tool always beats manual registry modifications. – Brian A. Henning Jul 18 '20 at 19:56
  • "Cannot check for updates because an error occurred while trying to contact the server" – John wantstoknow Feb 25 '21 at 11:56
  • I tried this first on a newly updated Win11 laptop. It did not work for me (errors trying to update NuGet Package Manager). so I added the `SchUseStrongCrypto` registry entries from another post which also did not work. After I restarted I tried updating NuGet Package Manager again and it worked this time. I'm no longer having the problem as the OP. Hard to say what actually fixed though, maybe both were needed in my case. – Jeff Mergler May 18 '22 at 23:51
8

NuGet has removed support for TLS 1.0 and 1.1 as of June 15, 2020. See https://devblogs.microsoft.com/nuget/deprecating-tls-1-0-and-1-1-on-nuget-org/

If you are using VS2013 or less you have lost NuGet connectivity as of this date and you will only be able to use NuGet by upgrading at least to VS2015, although I would suggest upgrading to VS2019 to be at the latest at time of this comment.

Rob Farquharson
  • 130
  • 1
  • 4
  • 2
    This is not in fact true as of July 7, 2020. Our team is still using VS 2013 and we were able to overcome the error by following the first answer that mentions adding entries to the registry. – Mitselplik Jul 07 '20 at 20:54
  • In my case adding to the registry did not solve the problem. Glad it did for you. However I upgraded my VS 2013 projects to VS 2019. I had to install a few extensions that I had in VS 2013 and other than that it worked well. I did first make a new git branch for the VS upgrade in order to optionally roll back. I noticed there were no git changes other than the code changes I put in myself. Very pleased with VS 2019. – Rob Farquharson Jul 13 '20 at 11:21
  • 1
    Yes same problem here with VS2013. Solved by adding registry entries as per top voted answer and restarting VS. – mike nelson Sep 08 '20 at 22:20
  • Fixed it for VS2012 (yay ancient company licenses) by adding the registry entry. Though I added it to the .Net 3.0 and 3.5 ones too for good measure. No idea if that actually does anything, but eh, it worked. – Nyerguds Apr 25 '22 at 07:01
2

This can also happen if you don't have TSL 1.0 enabled (disabled by default in Server 2012R2). In this case you may see some packages installing successfully before you hit the 'The underlying connection was closed: An unexpected error occurred on a send' error.

For more details on the error, run nuget install from the command line using "Verbosity detailed"

i.e.

System.Net.WebException: The underlying connection was closed: An unexpected err or occurred on a receive. ---> System.ComponentModel.Win32Exception: The client and server cannot communicate, because they do not possess a common algorithm

Tony Hinkle
  • 4,706
  • 7
  • 23
  • 35
2

The only thing that helped me was switching from Windows 7 to Windows 10. For people like me who don't really like updates details are described below.


As @Rob Farquharson have said above Nuget team threw away support for tls 1.0 and 1.1.

Some confusion is introduced by the fact that the https://api.nuget.org/v3/index.json opens perfectly through the browsers. Nevertheless, through Visual Studio we get an error "Unable to load the service index for source".

[nuget.org] Unable to load the service index for source https://api.nuget.org/v3/index.json. An error occurred while sending the request. The underlying connection was closed: An unexpected error occurred on a send. Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. An existing connection was forcibly closed by the remote host

This happens because the browser like Chrome and Firefox maintain and ship their own ciphers. .NET applications however rely on the ciphers provided by the OS. And therefore no action will help if support is not implemented at the OS level.

Neither suggestions here nor in the question Nuget connection attempt failed "Unable to load the service index for source" could help me. I've tried approximately 10 various ways to solve the desribed issue.

I've checked registry 3 times. Installed kb3140245 twice and did others stepd for activates tls 1.2, but none of them helped. Updating VS2019 from 16.4 (released in december 2019) to 16.11.8 (released in december 2021) didn't help either.

After that I installed brand new Windows 10 with Visual Studio 2019 and error went away.

1

This can happen if your firewall is doing SSL inspection. You may need to white list the repo.

0

Typically this is related to the webserver not having a valid SSL certificate. An invalid SSL certificate can be due to it being self-signed and not trusted by a CA, or the certificate has been revoked by the CA.

Using the unauthenticated URL can be a workaround for the issue however the solution to the problem is to ensure the SSL certificate is valid.

0

In my case, we have rules blocking .EXE downloads, so we keep a copy of NuGet.exe in the .nuget solution folder, right next to NuGet.targets and NuGet.Config

For whatever reason, this was missing in the new branch.

CZahrobsky
  • 762
  • 7
  • 7