DarthVader
DarthVader

Reputation: 55032

Nuget connection attempt failed "Unable to load the service index for source"

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

Answers (30)

StayOnTarget
StayOnTarget

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 under HKLM\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

Robert S.
Robert S.

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

Super Jade
Super Jade

Reputation: 6364

My error was

Nuget connection attempt failed "Unable to load the service index for source..."

Background

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.

Solution

  1. I updated Visual Studio 2022 to version 17.10.4 (This took about 30 minutes.)
  2. I signed in to my work account on VS, re-entering my credentials.
  3. Build succeeded!

Upvotes: -1

Victor SDK
Victor SDK

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

DomenicDatti
DomenicDatti

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

user2274515
user2274515

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

Pierre Thalamy
Pierre Thalamy

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

acmoune
acmoune

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

petrosmm
petrosmm

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

Ethan Seal
Ethan Seal

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

K. B.
K. B.

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

Peter PitLock
Peter PitLock

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

DrDoomPDX
DrDoomPDX

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

imsan
imsan

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

Daniel Williams
Daniel Williams

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:

https://learn.microsoft.com/en-us/answers/questions/959588/visual-studio-2022-won39t-connect-to-nuget.html

enter image description here

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

mindmischief
mindmischief

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

janonimus
janonimus

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

twasbrillig
twasbrillig

Reputation: 18831

I fixed this issue by installing IISCrypto and running this on command line:

IISCryptoCli.exe /template default /reboot

Upvotes: 1

Alper Ebicoglu
Alper Ebicoglu

Reputation: 9624

Disable your anti-virus application. In my case, AVG was preventing accessing nuget.org

Upvotes: 0

Harsha
Harsha

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

3rd party edit

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

Lemraj
Lemraj

Reputation: 379

In my case i lost the connection with Git. I just added the connection again and it worked!:

Connection to Team Explorer

Upvotes: 2

David Castro
David Castro

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

Hashka
Hashka

Reputation: 445

Simple :

  1. Close VS2019
  2. Go to C:\Users\you\AppData\Roaming\NuGet
  3. Delete the file NuGet.Config
  4. Relaunch VS2019

You're good to go !

Upvotes: 8

Shradha Shilvant
Shradha Shilvant

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

Prince Owen
Prince Owen

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.

Can't access the JSON file

Simply removing the nuget source from your settings should solve this issue

Removing Nuget Source from Visual Studio

Upvotes: 4

John Ranger
John Ranger

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

İlker Sevin&#231;
İlker Sevin&#231;

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:

  1. Download the package from its online source.
  2. Go to Tools/NuGet Package Manager/Package Manager Settings.
  3. Select Package Sources from the window.
  4. Add a new package source by clicking on the + sign. Enter a name and source location by clicking on ... (triple dot) sign.
  5. Make sure that only the package source that you've just added is checked. Uncheck all the other package sources.
  6. Go to Package Manager Console and type Install-Package Modernizr.
  7. Visual Studio 2015 installs the package automatically and creates Scripts and packages folders in your root folder.

I hope the same solution works while installing other packages, too.

Upvotes: 1

Eternal21
Eternal21

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

Turbcool
Turbcool

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

Vinod John
Vinod John

Reputation: 69

  1. go to %appdata%\NuGet\NuGet.config

  2. 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

Related Questions