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

Viewed 67036

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

9 Answers

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.

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

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.

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.

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.

Related