Reputation: 55032
While trying to connect to Nuget, I'm getting the error below, and then I am unable to connect:
[nuget.org] Unable to load the service index for source
https://api.nuget.org/v3/index.json.
An error occurred while sending the request.
Unable to connect to the remote server
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection
failed because connected host has failed to respond 68.232.34.200:443
I am able to access https://api.nuget.org/v3/index.json
on my browser.
Upvotes: 318
Views: 784763
Reputation: 13008
In my case, the problem was that Windows 7 has TLS 1.2 disabled by default.
I was building on an older Win7 virtual machine which had this issue.
I found this fix from https://github.com/NuGet/NuGetGallery/issues/8176#issuecomment-683923724 :
nuget.org started enforcing the use of TLS 1.2 (and dropped support for TLS 1.1 and 1.0) earlier this year. Windows 7 has TLS 1.2 disabled by default (check the
DisabledByDefault
value underHKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client
in your registry). To enable the support, please make sure you have an update (*) installed and switch the support on:reg add HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f /reg:32 reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f /reg:64 reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v Enabled /t REG_DWORD /d 1 /f /reg:32 reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v Enabled /t REG_DWORD /d 1 /f /reg:64
The (*) update referred to was Microsoft kb3140245: Update for Windows 7 (KB3140245)
I installed the update, rebooted (as requested by the update), added those registry keys, and then Nuget worked fine.
Upvotes: 7
Reputation: 2042
I got this error when calling dotnet restore
without any further error message. I usually use a VPN with a proxy but I wanted to do the restore without the VPN. In my case I had to set the environment variables HTTP_PROXY
and HTTPS_PROXY
to empty (you can do this temporarily inside your CMD/bash). Also use a fresh local nuget.config file like:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
Then I called dotnet restore --configfile nuget.config
. This ensures that no other nuget configs are considered. Usually there is a hierarchy and configs in parent directories or inside your appdata folder are also considered for proxy settings etc.
With all this I could ensure that it worked again.
Upvotes: 0
Reputation: 6364
My error was
Nuget connection attempt failed "Unable to load the service index for source..."
I had recently updated the password for my work account. I had re-entered my credentials in Visual Studio 2022, and it showed me signed in. However, this version of VS had a bug that did not update credentials as expected.
Upvotes: -1
Reputation: 473
Adding a nuget.config file in the root of my project solved this.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="NuGet Public" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
For more info go to Fixing NuGet error: Unable to load the service index for source - 401 Unauthorized
Upvotes: 1
Reputation: 662
I am adding this as an answer because I have a unique scenario someone else might encounter as well: I'm running Visual Studio and thus the dotnet/nuget.exe restore as a different user than my normal windows login. I had to run a terminal as that user and load the credential manager differently:
rundll32.exe keymgr.dll, KRShowKeyMgr
I found this here: https://www.top-password.com/blog/open-credential-manager-in-windows/
I had some bad credentials stored in there that were interfering with things. Once I removed those, that is when I was finally able to restore nuget packages on the command line, and then in Visual Studio.
Also, we use an on premise Azure Devops server, so even the Azure Credential Manager wouldn't work for me, though that was a potential fix as well, remembering to install the plugins into the other user's profile .nuget plugins. That might work for others if they're encountering this problem with a cloud devops setup.
Upvotes: 0
Reputation: 29
Tested on Windows 7
Step1 : Open Command window (run cmd) Step 2: Run the following commands to enable TLS 1.2 support if it is disabled (adding REGISTRY Entries):
reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f /reg:32
reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v DisabledByDefault /t REG_DWORD /d 0 /f /reg:64
reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v Enabled /t REG_DWORD /d 1 /f /reg:32
reg add "HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client" /v Enabled /t REG_DWORD /d 1 /f /reg:64
Upvotes: 2
Reputation: 681
This can also happen due to authentication issues, so you may need to re-authenticate to Visual Studio.
In that case, you can simply run the following command from the folder where your package.config
file is located (usually you project's root):
dotnet restore --interactive
You will be prompted to visit a pairing URL from your browser and enter a pairing code, for instance:
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code C2DEJ87H to
authenticate.
This requires the .NET CLI, which is included in the .NET Core SDK that can be installed from https://learn.microsoft.com/en-us/dotnet/core/install/windows
Furthermore, if no sign-in prompt appears upon running the nuget restore
command, your installation may be missing the artifacts-credprovider nuget plugin, which you can install with:
iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) }"
Upvotes: 51
Reputation: 3411
In my case, it was due to a change in my network configuration. The ultimate solution is to restart your computer.
Upvotes: 0
Reputation: 550
If anyone is still having trouble and the NuGet answers are not working. The following answer worked for me (a company DevOps Azure hosted TFS): sign in and out of teams foundation. TFS and VS both reported as signed in but turns that was not the case. Had to resign in -- same symptoms as described by OP. See this answer for more details.
Upvotes: 1
Reputation: 31
The answers that say to just delete Nuget.Config won't work if you're using a custom feed. If you're using a custom feed, you need to edit the Nuget.Config file to point to the index of your custom feed.
Upvotes: 0
Reputation: 3690
I deleted everything in %localappdata%/Nuget and cleared the NuGets cache.
dotnet nuget locals all --clear
After restart, Visual studio 2022 restored my packages.
Upvotes: 2
Reputation: 1873
I had to run dotnet restore in command prompt from the folder where the .sln is located, which worked successfully (while VS failed restoring the nuget packages). After this, I was able to list the Installed packages under Visual Studio at least, but "Updates" was still failing to load.
Upvotes: 0
Reputation: 312
In my case, it was that I was unknowingly logged out of my work account altogether. Logging back into my visual studio account resolved it.
Upvotes: 11
Reputation: 449
I spent a day on this and tried everything here. For me it was that I didn't update my password in Visual Studio!
I had changed my work Microsoft account password last week or so, I also use that account to login to visual studio, however I wasn't prompted to update it and was not logged out of Visual Studio, it remained logged in. When I clicked on my initials in the top right of visual studio > Account settings > under All Accounts the work account had yellow exclamation triangle warning sign next to it, updated the new password, then updated some packages, dotnet restore, cleaned & rebuilt and the errors are gone.
Upvotes: 4
Reputation: 9304
OK I tried all the answers above and hope my registry is not now hosed. But this appears to have fixed it for me:
Add this: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
To the comma-separated string in this:
HKLM\SOFTWARE\Policies\Microsoft\Cryptography\Configuration\SSL\00010002
I hope this helps the next person who hope to make a fun quick Saturday morning proof-of-concept, and then winds up spending 3 hours searching for a fix!!!
Upvotes: 2
Reputation: 271
I have a couple Windows 2016 Servers where Visual Studio couldn't connect to NuGet. After trying virtually every other suggested fix (registry changes, Visual Studio/NuGet related cache clearing or file/config changes), the below is what resolved it for us.
We have a Group Policy (GPO) with the ciphers set and I added these ciphers to our GPO cipher list for it to work.
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
https://github.com/NuGet/Announcements/issues/60
Upvotes: 2
Reputation: 2877
Deleting %AppData%\Roaming\NuGet\NuGet.Config
and restarting VS2019 worked for me.
Similar to https://github.com/NuGet/Home/issues/3281
Upvotes: 253
Reputation: 18831
I fixed this issue by installing IISCrypto and running this on command line:
IISCryptoCli.exe /template default /reboot
Upvotes: 1
Reputation: 9624
Disable your anti-virus application. In my case, AVG was preventing accessing nuget.org
Upvotes: 0
Reputation: 569
A developer of the nuget-package manager suggested in 2019 to disable tls 1.3 as a workaround (see issue 7705).
Open Registry Editor by pressing Win + R and type regedit
Enter
Navigate to:
\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client
Change the value of DisabledByDefault
key 0 to 1
Then restart the Visual Studio.
Read more about TLS on wikipedia
Read more about issue 7705 w.r.t. NuGet at github
Be aware that this disables tls 1.3 for the os not just for nuget or dotnet.
Windows 10 version 1909 did contain an experimental implementation of TLS 1.3 but later versions should be fine. Based on one answer from Unable to browse nuget packages you can test if tls is the problem via a console programm
static async Task Main(string[] args)
{
var client = new HttpClient();
string uri = "https://apiint.nugettest.org/v3-index/index.json";
var response = await client.GetAsync(uri);
string msg = "If you see this, your machine has no TLS/SSL issues with nuget.org";
Console.WriteLine(msg);
}
Upvotes: 37
Reputation: 379
In my case i lost the connection with Git. I just added the connection again and it worked!:
Upvotes: 2
Reputation: 1967
If you are a Windows user, you may either remove or update your credentials in Credential Manager.
In Windows 10, go to the below path:
Control Panel → All Control Panel Items → Credential Manager
Or search for "credential manager" in your "Search Windows" section in the Start menu.
Then from the Credential Manager, select "Windows Credentials".
Credential Manager will show many items including your outlook and GitHub repository under "Generic credentials"
You click on the drop down arrow on the right side of your Git: and it will show options to edit and remove. If you remove, the credential popup will come next time when you fetch or pull. Or you can directly edit the credentials there.
Upvotes: 3
Reputation: 445
Simple :
C:\Users\you\AppData\Roaming\NuGet
NuGet.Config
You're good to go !
Upvotes: 8
Reputation: 509
I was getting the same error while trying to browse the NuGet Package, to resolve the same followed below step:
1- go to %appdata%\NuGet\NuGet.config
2- Verify the urls mentioned in that config
3- Remove the url which is not required
4- Restart visual studio and check
Upvotes: 50
Reputation: 1505
One of your nuget sources may be unreachable.
At the moment of writing, AspNetCore (https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json) seems to have an expired certificate or have been removed entirely.
Simply removing the nuget source from your settings should solve this issue
Upvotes: 4
Reputation: 633
I tried many of the listed answers here but these didn't resolve the problem. In the end, I had to go to the credential manager in Windows and delete the VSCredentials_xxx entry under "Windows Credentials" and restart Visual Studio 2019.
After that - on the next VS start - VS finally asked me for my proxy credentials - and after entering them, access to the internet for Visual Studio worked.
(It seemed that VS did store my initially given proxy credentials long ago - but because in our company they have password change after 3 months enforced - the credentials were no longer valid.)
Upvotes: 2
Reputation: 11
I had a similar problem while trying to execute Install-Package Modernizr on Visual Studio 2015. I fixed my problem by following the below steps:
Install-Package Modernizr
.I hope the same solution works while installing other packages, too.
Upvotes: 1
Reputation: 4664
I encountered this error when trying to set up NuGet packages inside locally hosted Gitlab instance. The error indicated 401 Unauthorized code. The solution was removing offending source with:
nuget source Remove -Name SOURCE_NAME
And then adding the same source, but this time specifying the username and password in the command:
nuget source Add -Name SOURCE_NAME -Source SOURCE_URL -UserName GITLAB_DEPLOY_TOKEN_USERNAME -Password GITLAB_DEPLOY_TOKEN
Upvotes: 0
Reputation: 114
I couldn't resolve the problem itself, but found a way to install packages.
Just specify nuget.org as a source directly in Package Manager Console
.
Update-Package -reinstall -Source nuget.org
Upvotes: 0
Reputation: 69
go to %appdata%\NuGet\NuGet.config
Modify this line:
<packageSources>
<add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
<add key="Package source" value="https://api.nuget.org/v3/index.json" />
</packageSources>
Upvotes: -2