0

I'm using a Nuget package that itself references a previous version of System.Reactive (specifically 4.3.2). I am not the maintainer and cannot change that, but would still like to use the package. However, all the projects in my solution reference a newer version of System.Reactive (5.0.0), and I am currently not at liberty to change that. This leads to a versioning conflict.

Back in the day I would use binding redirects, but we've transitioned to .NET Core and PackageRefernces recently, and it's unclear to me how I resolve such version conflicts using PackageReferences.

Two closely (I would assume) related questions then:

  1. Is it possible to resolve the above scenarion, and if so, how?
  2. How would one resolve the reverse situation (newer version in external package, older version in my solution/projects)?
10
  • The way you've described it this should be fine (note that when you have a single version on a package reference you're actually saying you're happy to have any version greater than or equal to that, not specifying a concrete single version). If you post your error you'll probably have a better chance of getting an answer Feb 9, 2021 at 23:44
  • @rbennett485: I don't see how it should be expected to be fine - specifying a version number doesn't mean "any version greater" in SemVer terms, even if NuGet treats it that way. I would expect there to be breaking changes between 4.x and 5.x, and we have no way of knowing whether the package the OP is depending on will be broken by those breaking changes.
    – Jon Skeet
    Feb 10, 2021 at 12:32
  • @JonSkeet it's not clear from the question but I'm assuming a versioning conflict means an error from NuGet resolving versions rather than a runtime exception from binary incompatibilities between major semver versions Feb 11, 2021 at 12:31
  • @rbennett485: I would say that even if it doesn't lead to an error from NuGet, there's still fundamentally a version conflict, just potentially masked by NuGet. I certainly wouldn't describe the situation as "this should be fine". Maybe "this shouldn't cause NuGet resolution a problem" but that's a long way from being "fine".
    – Jon Skeet
    Feb 11, 2021 at 12:40
  • @JonSkeet that's probably reasonable for system packages, but in general publishers of NuGet packages are so bad at semver that I'm inclined to agree with the NuGet tooling's model of treating major bumps as the same as any other Feb 11, 2021 at 12:47

2 Answers 2

4

Fundamentally, because you're resolving against two different major versions, there's currently no pleasant way of resolving this.

The fact that System.Reactive went from 4.x to 5.x suggests there are breaking changes, assuming it's actually following SemVer. So it's entirely possible that the package you're depending on relies on something in System.Reactive that was removed in 5.0.

Unless you want to get into loading the assemblies yourself using AssemblyLoadContext as a sort of isolation level, you're basically out of luck. .NET simply doesn't handle this situation well at the moment.

I suggest you work out the least painful way of getting everything onto the same major version. This could mean:

  • Downgrading your System.Reactive dependency
  • Persuading the maintainer of the other package to upgrade their System.Reactive dependency (which will mean them creating a new major version as well...)
  • Forking the other package so that you can upgrade its System.Reactive dependency yourself

None of these is likely to be simple, unfortunately.

1
  • Thanks @JonSkeet - I was afraid that would be the answer but I do appreciate you outlining my options. Time to annoy the maintainer then, I guess! Feb 10, 2021 at 12:59
1

When using .NET Core, you should find binding redirects unnecessary in this case.

I'll refer you to https://learn.microsoft.com/en-us/nuget/concepts/dependency-resolution#dependency-resolution-with-packagereference

If you are getting a nuget failure, you likely need to add a direct PackageReference to the problematic library, in order to enforce "Nearest wins" behaviour. I'm assuming the structure is something like:

Project:
  -> NugetPackage1
    -> System.Reactive (=5.0.0)
  -> NugetPackage2
    -> System.Reactive (=4.3.2)

and the suggested change would be to make it into:

Project:
  -> NugetPackage1
    -> System.Reactive (=5.0.0)
  -> NugetPackage2
    -> System.Reactive (=4.3.2)
  -> System.Reactive (5.0.0)

(Please note that this kind of failure only happens if the package requirements explicitly conflict - in this case both packages want a specific version, rather than simply a version greater than X.)

Note that if you wanted to make the direct PackageReference the lower of the two versions, that would work as well.

If the versioning conflict is a runtime exception, please post the exception.

2
  • This isn't quite right - your first example is resolvable (NuGet picks v5.0.0), and in your second if you were to directly reference the lower of the two versions you'd get a package reference downgrade Feb 9, 2021 at 23:41
  • Thanks for your helpful comment. I've updated the answer to hopefully make it correctly unresolvable for nuget. With regards to the package reference downgrade - yes, you would get a warning for this. I assumed that if the user wanted this behaviour, they'd be fine with getting the warning. Feb 10, 2021 at 17:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.