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
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
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.
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
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.
This can happen if your firewall is doing SSL inspection. You may need to white list the repo.
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.
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.