0

In my project I have a package A using System.Runtime.CompilerServices.Unsafe v>=5.0.0, and another package B using System.Runtime.CompilerServices.Unsafe v=4.5.3.

When I try to install System.Runtime.CompilerServices.Unsafe v=4.5.3 from the NuGet Package Manager I get the following error:

Detected package downgrade: System.Runtime.CompilerServices.Unsafe from 5.0.0 to 4.5.3. Reference the package directly from the project to select a different version.

I found information related to this issue at https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1605, where it is suggested to add a PackageReference of the needed version.

I tried to add reference for the 4.5.3 version or for both versions, yet nonE of these solutions seem to work.

Am I doing something wrong? How is it possible to use two different versions of the same package in one project?

  • .net 5 != .net 4.5 => upgrade all of your projects to support 5.0 or downgrade :) – Dimi Takis Dec 06 '21 at 09:57
  • Have a look at this answer : https://stackoverflow.com/a/67784313/2111137 – Connor Stoop Dec 06 '21 at 09:58
  • 1
    Basically you can't use two different versions of the same package. It's unclear what your project structure is at the moment, which makes it hard to help you - but I'd expect that if you have a project C that relies on both A and B, it should be fine - it'll just use 5.0.0. (I'd expect that to be compatible with 4.5.3, as Microsoft *usually* avoids breaking changes in System packages, even across major versions.) – Jon Skeet Dec 06 '21 at 10:00
  • Thanks for your answers! I am actually trying to use IronPython, which seems to need 4.5.3 as my code crashes trying to find: `'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1` (corresponding to v 4.5.3 as explained here https://stackoverflow.com/questions/62764744/could-not-load-file-or-assembly-system-runtime-compilerservices-unsafe) – Thomas Bonte Dec 06 '21 at 10:24

0 Answers0