nuget.org: Unable to load the service index
Asked Answered
R

3

7

This is not really a Duplicate to this question as the answers provided are not working and I am using Windows-7 on a MacBook using Bootcamp.

I am getting the following error while trying to search any package in the Nuget Package Manager:

Severity Code Description Project File Line Suppression State Error [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

My NuGet Config File (%appdata%/nuget):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>
Retinitis answered 18/4, 2022 at 13:8 Comment(4)
Can you even reach that URL on your windows install?Sparky
@Sparky Yes, I am able to access thw URL in a browserRetinitis
@Retinitis I have the same issue, but I'm using VS on VirtualBox Win 7 VM. Did you solve your problem?Irresponsible
@Retinitis this answer helped me https://mcmap.net/q/107442/-nuget-connection-attempt-failed-quot-unable-to-load-the-service-index-for-source-quotIrresponsible
E
5

Nuget.org started enforcing the use of TLS 1.2 (and dropped support for TLS 1.1 and 1.0). 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

Epicritic answered 1/8, 2022 at 21:52 Comment(3)
This post saved my lifeEnrollment
Updating VS fixed it for meLupus
Mark it as the answer if it fixed your issue.Epicritic
U
4

Well.. let me try if this can save your day. I faced the same issue, and I tried everything mentioned in this post and few related posts (started 5-6 years ago) mentioned below, but unfortunately nothing worked.. until I had a trick that solved my problem. This could be a temp solution but could save hours if this glitch is caused by some Windows update or network policy or Anti Virus and what not!

My situation: One of my few development PCs (Win11, Win10) with VS 2022 (17.7.5) started showing this error when building the solution from Visual Studio:

[nuget] unable to load the service index for source https://api.nuget.org/v3/index.json. an error occurred while sending the request. the remote name could not be resolved: 'api.nuget.org'

Interestingly the same was working on other PCs. I spent many hours debugging and following the below threads. Did many reboots, restarts.. nothing helped. Even I tried downloading VS 2019 to confirm and the same issue showed up.

C:\Windows\System32> ping api.nuget.org
Ping request could not find host api.nuget.org. Please check the name and try again.

So I realized this is a network thing that messed up on one of my PCs and it was not able to resolve the DNS for api.nuget.org. I'm coding for more than 2 decades but still the IP config and other networking stuff freaks me out!

My Solution: I ran this on a good PC (command prompt):

C:\Windows\System32>ping api.nuget.org
Pinging part-0010.t-0009.t-msedge.net [13.107.246.38] with 32 bytes of data:
Reply from 13.107.246.38: bytes=32 time=71ms TTL=57
Reply from 13.107.246.38: bytes=32 time=19ms TTL=57
...

and added this to the hosts file on the bad PC (C:\Windows\System32\drivers\etc):

13.107.246.38   api.nuget.org

...and boom!!!

Related posts (I tried all answers and it didn't work for me):

Underlaid answered 18/10, 2023 at 4:9 Comment(1)
This is the only thing that worked for me after trying about every other solution I found on the internet for hours.Allyl
M
0

For me rebuilding the solution or the project worked.

Motherly answered 28/7 at 16:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.