warning NU1900: Error occurred while getting package vulnerability data: Unable to
load the service index for source ... means NuGet's audit could not ask one of your
package sources for its list of known vulnerabilities. In this test the packages still
restored; only the audit step failed. Remove or repair the source it names, or tell NuGet
which sources to audit against with <auditSources>.
It is a warning, so a normal restore went on and exited 0. With
TreatWarningsAsErrors on, the same line became error NU1900 and
the restore failed.
The error
dotnet restore --force
Determining projects to restore...
C:\...\Nu1\Nu1.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source http://127.0.0.1:15641/v3/index.json.
Restored C:\...\Nu1\Nu1.csproj (in 17.74 sec).
exit=0
The paths are shortened; nothing else changed. Note the time: 17.74 seconds for a project with one package, against under a tenth of a second once the source was gone.
Why it happens
The project's own nuget.config listed a second source that nothing answered
on, standing in for a company feed that is down, a VPN that is off or a local feed folder
server that was never started:
...
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="fix11-dead-feed" value="http://127.0.0.1:15641/v3/index.json" allowInsecureConnections="true" />
</packageSources>
...
The one package, Newtonsoft.Json 13.0.4, was already in the global packages
folder:
dotnet nuget locals global-packages --list
global-packages: C:\Nuget
exit=0
dir /b C:\Nuget\newtonsoft.json\13.0.4\*.nupkg
newtonsoft.json.13.0.4.nupkg
exit=0
The restore succeeded with the dead source listed, and the only line about that source
was the NU1900 warning. The two runs that removed the warning point at where it came
from: removing the source, or keeping it and adding <auditSources>
that name only nuget.org. For a restore that fails on a source, see
the NU1301
post.
The fix
If the source is not needed, remove it:
...
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
...
dotnet restore --force
Determining projects to restore...
Restored C:\...\Nu1\Nu1.csproj (in 92 ms).
exit=0
If the source must stay (it serves packages when it is up), keep it and name the audit source on its own. With the dead source still listed, this addition made the warning go away:
...
</packageSources>
<auditSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</auditSources>
...
dotnet restore --force
Determining projects to restore...
Restored C:\...\Nu1\Nu1.csproj (in 72 ms).
exit=0
How it was reproduced
A console project from dotnet new console -f net10.0 with SDK 11.0.100 on
Windows 11 and Newtonsoft.Json 13.0.4. A nuget.config in the
project folder, starting with <clear />, listed nuget.org and
http://127.0.0.1:15641/v3/index.json, a port with nothing listening.
dotnet restore --force ran four times: with the dead source, with
<auditSources> added, with the source removed, and with the source back
and -p:TreatWarningsAsErrors=true, which printed error NU1900: Warning
As Error and Failed to restore with exit code 1.
Every command shown without a PS> marker ran in cmd: a PowerShell script passed it as cmd /c ... 2>&1 and printed the exit= line after it.
Frequently asked
- Does NU1900 stop the build?
- Not by itself. In this test the restore printed warning NU1900 and still restored with exit code 0. With TreatWarningsAsErrors set, the same line became error NU1900 and the restore failed with exit code 1.
- How do I fix NU1900 Error occurred while getting package vulnerability data?
- Look at the source URL at the end of the line. In this test removing that source from nuget.config, or keeping it and adding an auditSources section that names only nuget.org, each made the warning go away.
- Why is dotnet restore slow when NU1900 appears?
- In this test the restore with the unreachable source took 17.74 seconds for one package, and under a tenth of a second once the source was removed or auditSources was set.
More decoded errors in the Fixes category. For the warning a vulnerable package gives, see NU1903.