Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit reference to System.Runtime.CompilerServices.Unsafe appears to cause wrong version to be selected #72

Closed
gibbed opened this issue Jun 28, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@gibbed
Copy link

gibbed commented Jun 28, 2022

Description

The implicit package reference seems to be causing VS to pick an older version 4.5.3 of System.Runtime.CompilerServices.Unsafe on newer NuGet releases (after 1.2.6) at least with .NETFramework,Version=v4.5 and .NETFramework,Version=v4.6.

This causes a type loading error.

The relevant commit that introduced this issue appears to be a6a7580.

To reproduce

Attempting to use the library from NuGet package versions 1.2.12, 1.2.13, 1.2.15, or 1.2.16.

Expected behavior

No issues.

Actual behavior

A type loading exception will be thrown.

System.TypeInitializationException: 'The type initializer for 'K4os.Compression.LZ4.Engine.LL' threw an exception.'

FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

System.Runtime.CompilerServices.Unsafe for version 4.5.3 gets copied to the output path of the project.

Environment

  • CPU: AMD Ryzen 9 3900X (64-bit)
  • OS: Windows 10 Pro (21H2)
  • .NET: .NET Framework 4.5, 4.6
  • LZ4: 1.2.12, 1.2.13, 1.2.15, 1.2.16

Additional context

Explicitly installing the NuGet package for System.Runtime.CompilerServices.Unsafe, version 5.0.0 (possibly 6.0.0 too but I didn't try it) works around this problem. I'm not sure if this is the intended path, I didn't see it mentioned in the README.

@MiloszKrajewski
Copy link
Owner

I can confirm the problem.
This System.Runtime.CompilerServices.Unsafe is a PITA.
It was explicitly referenced, but for new .NET Core it is built-in so referencing it was causing conflicts sometimes, so I removed it and trusted .NET to pick the right one. Now I can see it cannot be trusted.

So, it will return as explicit, but in the meantime just add explicit reference to your project.

@MiloszKrajewski
Copy link
Owner

Hopefully sorted out in 1.3.0-beta

MiloszKrajewski added a commit that referenced this issue Nov 6, 2022
@MiloszKrajewski
Copy link
Owner

Finally fixed in 1.3.3-beta. Tested with: net461, net48, netcore20, netcore31, net6
Check this

@MiloszKrajewski MiloszKrajewski removed their assignment Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants