NuGet fails: "The underlying connection was closed: An unexpected error occurred on a send"
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.
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
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
Solved it by going to Tools -> Extensions and Updates... -> Updates -> Visual Studio Gallery and Updated NuGet Package Manager from there.
After reboot everything worked:
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.