Error NU1605 Detected package downgrade

.NetVisual Studio-2017.Net CoreNuget.Net Core-2.0

.Net Problem Overview


I am experiencing the following NU1605 dependency errors in my netcoreapp2.0 console application:

NU1605	Detected package downgrade: System.Diagnostics.Debug from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version. 
 MyProject -> Colorful.Console 1.2.6 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Diagnostics.Debug (>= 4.3.0) 
 MyProject -> System.Diagnostics.Debug (>= 4.0.11)

NU1605	Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. 
 MyProject -> Colorful.Console 1.2.6 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Runtime.Extensions (>= 4.3.0) 
 MyProject -> Colorful.Console 1.2.6 -> System.Runtime.Extensions (>= 4.1.0)	MyProject

NU1605	Detected package downgrade: System.Runtime.Handles from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version. 
 MyProject -> Colorful.Console 1.2.6 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Runtime.Handles (>= 4.3.0) 
 MyProject -> Colorful.Console 1.2.6 -> System.IO.FileSystem 4.0.1 -> System.Runtime.Handles (>= 4.0.1)

NU1605	Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. 
 MyProject -> Colorful.Console 1.2.6 -> System.Console 4.0.0 -> runtime.win.System.Console 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0) 
 MyProject -> Colorful.Console 1.2.6 -> System.Runtime.InteropServices (>= 4.1.0)

I have tried referencing these package versions in csproj, but this doesn't fix the problem. See csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Colorful.Console" Version="1.2.6" />
    <PackageReference Include="CommandLineParser" Version="2.2.1" />
    <PackageReference Include="DotSpinners" Version="1.2.0" />
    <PackageReference Include="System.Diagnostics.Debug" Version="4.0.11" />
    <PackageReference Include="System.Runtime.Extensions" Version="4.1.0" />
    <PackageReference Include="System.Runtime.Handles" Version="4.0.1" />
    <PackageReference Include="System.Runtime.InteropServices" Version="4.1.0" />
  </ItemGroup>
</Project>

And they do seem to restore fine:

Package References

The project is also referencing the Microsoft.NETCore.App 2.0 SDK.

When performing dotnet restore from the CLI, I also get the following error, which I am not sure is related:

C:\Program Files\dotnet\sdk\2.1.200\NuGet.targets(114,5): error : Failed to retrieve information about 'System.Runtime.Serialization.Formatters' from remote source 'https://mycompany.pkgs.visualstudio.com/_packaging/myid/nuget/v3/flat2/system.runtime.serialization.formatters/index.json'. [C:\MyProject\MyProject.sln]
C:\Program Files\dotnet\sdk\2.1.200\NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\MyProject\MyProject.sln]

I have no idea why it's trying to retrieve information about 'System.Runtime.Serialization.Formatters' from our private company package repository.

NuGet.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="mycompany" value="https://mycompany.pkgs.visualstudio.com/_packaging/Stable/nuget/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
     <mycompany>
       <add key="Username" value="vsts" />
       <add key="ClearTextPassword" value="xxx" />
     </mycompany>
   </packageSourceCredentials>
  <disabledPackageSources>
    <add key="Microsoft and .NET" value="true" />
  </disabledPackageSources>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageManagement>
    <add key="format" value="0" />
    <add key="disabled" value="False" />
  </packageManagement>
</configuration>

I also have the following NU1603 warning if this means anything:

NU1603	MyProject depends on System.Runtime.Handles (>= 4.1.0) but System.Runtime.Handles 4.1.0 was not found. An approximate best match of System.Runtime.Handles 4.3.0 was resolved.

.Net Solutions


Solution 1 - .Net

I had a similar issue with a .netcoreapp2.2 console application.

The project was building successfully. However, publishing was failing with several NU1605 errors.

The problem was originated from log4net version 2.0.8. It was referenced in a .netstandard2.0 project with the following dependencies:

log4net v2.0.8 does not include specific dependency for .NetStandard,Version=2.0

They were causing package downgrades in the projects referencing log4net. And during publish these warnings are treated as errors...

To solve the problem I added correct versions of these libraries via Nuget.

log4net dependencies and additional nuget packages for version errors

Finally, the publishing succeeded.

P.S. When I first added packages with the newest version of libraries, a yellow warning sign was displayed on the dependencies list as if the packages were not suitable for that project. After unloading the project and loading back the warning sign gone! (I'm using Visual Studio 2019)

Solution 2 - .Net

> Error NU1605 Detected package downgrade

For the error NU1605:

You can use <NoWarn>NU1605</NoWarn> to clear the WarningsAsErrors in your project.

That because netcoreapp2.0 projects have <WarningsAsErrors>NU1605</WarningsAsErrors> by default. Check it from Properties->Build->Treat warning as errors:

enter image description here

Add like following:

<PackageReference Include="Colorful.Console" Version="1.2.6">
      <NoWarn>NU1605</NoWarn>
</PackageReference>

Check the blog post here: MSBuild integration of NuGet warnings and errors and Unexpected package version warnings.

For the error NU1603:

The warning occurs because System.Runtime.Handles (>= 4.1.0) does not exist in the feed. Typically this is a package authoring error because the package depends on something that doesn't exist.

You can also use <NoWarn>NU1603</NoWarn> to resolve this issue:

<PropertyGroup>
      <NoWarn>NU1603</NoWarn>
</PropertyGroup>

Note:You would notice that your project has another warning, notice the yellow triangle insignia on the PackageReference DotSpinners on Reference. That because the package DotSpinners is a .NET Framework project, not compatible with your .NET Core project.

Solution 3 - .Net

Just had the same issue (NU1605) with .Net core 3.1 and log4Net:

> error NU1605: Detected package downgrade: System.Net.NameResolution from 4.3.0 to 4.0.0.

What I did is adding a Nuget reference to System.Net.NameResolution and install version 4.3.0, then I closed Visual Studio and re-opened the Solution.

Solution 4 - .Net

All of the above did not help me with my .NET Core 3.1 project.

The error NU1605 reappeared again and again after complete recompilation. All references to the version number have been correct in the csproj file.

What finally helped was to delete the obj folder!

Afterwards the recompilation worked without problems.

Solution 5 - .Net

Make sure that you are using same version for build and publish you can fix it adding 2.1.9 in .csproj file under PropertyGroup this should match with your current settings version. Ex:

  <PropertyGroup>
      <OutputType>Exe</OutputType>
      <TargetFramework>netcoreapp2.1</TargetFramework>    
      <RuntimeFrameworkVersion>2.1.9</RuntimeFrameworkVersion> 
  </PropertyGroup>

Error which I got was: NETSDK1061: The project was restored using Microsoft.NETCore.App version 2.1.9, but with current settings, version 2.1.0 would be used instead.

Solution 6 - .Net

Something that I've run into that causes this error is having multiple references to the same package in one or more .csproj files. In our case, these references are to local dependencies in our own nuget repository.

This is invisible to a developer in Visual Studio, so you need to open the .csproj file in a separate editor.

For my team, I think the cause is a combo of a lot of churn in both a dependent library and the solution that consumes that dependency. For whatever reason, a git merge will take both versions in the .csproj file without raising a conflict. In several project files, I found 3 versions of the same dependency.

Solution 7 - .Net

There are already a bunch of answers to the question, many of them fixing the problem, but I think the solution I applied is cleaner than everything else I saw online.

As stated, the usual suspect of the error in .Net Core 3.1 is some assembly depending upon a library requiring a System.* or Microsoft.* assembly.

When the build runs, everything can be fine, because the resolution of assemblies is using only project references.
When a "Publish" build is performed, with a runtime selected, the resolution of assemblies doesn't follow the algorithm used by Nuget when restoring, so the Warning creeps up.

From this situation, follows my solution: when we perform a build with a target runtime, we want to enforce that the correct runtime version is selected.

In the .csproj file, I added this:

<!-- adjust runtime and package version accordingly -->
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'win-x64' ">
  <PackageReference Include="Microsoft.NETCore.Targets" Version="3.1.0" />
</ItemGroup>

The Microsoft.NETCore.Targets package, found at this link (which has lots of info on the warning) is one of the solutions to the dreaded warning, and having it included only in the publish build keeps all the other builds untouched. The nice thing of this package is that it is one package, and includes all the runtime.

Solution 8 - .Net

I had this problem with a .Net Core 2.2 project using a .Net Standard 2.0 DLL in the same solution. I had the errors reported for the .Net Standard DLL when I added several SeriLog packages to the .Net Core application. I backed out the changes, then added the SeriLog packages one-by-one, cleaning and rebuilding between each addition. This time there was no error...

Solution 9 - .Net

I am not sure if this is the best option or the way to fix this problem, but i had the same issue:

> NuGet Warning NU1605 (package downgrade)

My process of elimination was to make sure my project was:

  1. Saved
  2. Build Solution (ctrl shift b) (only error was the NU1605)
  3. Right click project folder, click into Manage NuGet packages.
  4. Click on Updates, I personally updated all packages.
  5. (Step 2 again).

This was all i needed to do. Hopefully this was the same outcome.

Solution 10 - .Net

The GraphQL nuGet package I was referencing had a dependency to Newtonsoft.Json(>= 10.0.3). The only solution was the following:

  • Remove the GraphQL nuGet package.
  • Install the latest NewtonSoft.Json package v12.0.3
  • Go back and reinstall the GraphQL nuGet package.

Solution 11 - .Net

Somewhy dotnet restore brings dependency warnings only on RuntimeIdentifier:win10-x64. portable runtime works normally.

Solution 12 - .Net

I faced a similar problem (NU1605) when publishing but I figured out was the runtime linux-x64. So I removed the runtime option and the problem has gone.

Solution 13 - .Net

I had a similar issue, where my project had package reference like this:

Package references:

  • Package A
  • Package B
    • Package A

So because project B reference package A, I just deleted package A from the main packages list and was left with Package B referencing Package A. I rebuilt the solution and the problem was gone.

Solution 14 - .Net

I had this problem when adding a Connected Service reference to an ASP.Net Webservice. Added this reference in project Nop.Plugin.SDE causing a reference to System.ServiceModel.Http 4.4.4 to be added, while it already was referencing project Nop.Services having a reference to System.ServiceModel.Http 4.7.0. The solution was to upgrade the reference to System.ServiceModel.Http to version 4.7.0 from project Nop.Plugin.SDE.

Solution explorer after adding reference

Upgrade System.ServiceModel.Http from 4.4.4 to 4.7.0

Reference to System.ServiceMode.Http from Nop.Services

Solution 15 - .Net

After going through all the advices above, and taking reference from the accepted answer from @Mert, what worked for me was deleting the specific package that was causing the inconsistency.

enter image description here

Inside package folder, visual studio very helpfully marks the package causing the issue with a yellow warning sign.

I deleted the package and used NuGet to install the appropriate version of the package.

Solution 16 - .Net

I ran into NU1605 with .NET 5 while trying to update a Nuget package.

The solution to Example 2 in this article worked perfectly for me.

In short, I only had to add

<PackageReference Include="Microsoft.NETCore.Targets" Version="5.0.0" PrivateAssets="all" />

to the ItemGroup of the project, which was the target of the update (in VS, the relevant .csproj appeared when I doubleclicked on the "Detected package downgrade" error message).

Solution 17 - .Net

may be some one added a new project with new version and there may be some project with old version. upgrading all the projects to the same version would fix the issue.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDave NewView Question on Stackoverflow
Solution 1 - .NetMert Can IlisView Answer on Stackoverflow
Solution 2 - .NetLeo Liu-MSFTView Answer on Stackoverflow
Solution 3 - .NetarielhadView Answer on Stackoverflow
Solution 4 - .NetFrankensteinView Answer on Stackoverflow
Solution 5 - .NetPRathoreView Answer on Stackoverflow
Solution 6 - .NetStuartView Answer on Stackoverflow
Solution 7 - .NetA. ChiesaView Answer on Stackoverflow
Solution 8 - .NetMark WillisView Answer on Stackoverflow
Solution 9 - .NetJonesView Answer on Stackoverflow
Solution 10 - .NetJames LawrukView Answer on Stackoverflow
Solution 11 - .NetOlegView Answer on Stackoverflow
Solution 12 - .NetgandarezView Answer on Stackoverflow
Solution 13 - .NetYair A.View Answer on Stackoverflow
Solution 14 - .NetSteefView Answer on Stackoverflow
Solution 15 - .NetfanbyprincipleView Answer on Stackoverflow
Solution 16 - .NetTvdHView Answer on Stackoverflow
Solution 17 - .Netlast-ProgrammerView Answer on Stackoverflow