Napo
Napo

Reputation: 21

dll dependency problem - 3rd party package(Nuget) overrides the other in the output folder System.Runtime.CompilerServices.Unsafe dll

Goal: control the output dll without saving or adding the artifact to the repository.

The main issue is that I have two 3rd party packages in my solution (.net framwork 4.6.1): rabbitMQClient V6.0.0 that use - system.memory (>= 4.5.4) -> System.Runtime.CompilerServices.Unsafe (>= 4.5.3)

MongoBson v2.12.1 that use System.Runtime.CompilerServices.Unsafe (>= 5.0.0) (for example)

every package provide the following System.Runtime.CompilerServices.Unsafe.dll with different version and since they are different project every one of them overrides the other in the output directory.

what I tried: If I try to downgrade the "CompilerServices.Unsafe" the mongoDb connection failed due to exception - The type initializer for 'MongoDB.Driver.Core.Misc.DnsClientWrapper..."

if I upgrade then the rabbit won't connect - inner exception: Could not load file or assembly.

I tried to use redirect but it seems that its not working (rabbitMq exception if its the new version of the dll)

The only possibility for the solution to work is if I set the copy local to false at all the projects except the project that uses the old version but since at NuGet update it will set to true I need more stable solution.

Upvotes: 2

Views: 490

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064114

Downgrade is not a viable option; upgrade should usually work but you'll need to fix the assembly bindings; System.Runtime.CompilerServices.Unsafe is well-known as one of those that is a major pain here, complicated by the fact that the auto-binding generation code just doesn't work right for it; Nick has good guidance on how to do this here - and the main config examples happen to use System.Runtime.CompilerServices.Unsafe, so it should just be a case of adding the current version numbers.

This is one of many many things that just gets a lot easier in .NET Core / .NET 5 onwards.

Upvotes: 1

Related Questions