C# "No way to resolve conflict between X and Y"

I have the following solution structure:

Solution    
      \_ProjectA
      \_ProjectB (uses 3rd party DLL v1)
      \_ProjectC (uses 3rd party DLL v2)

Project A has no direct reference to the 3rd party DLL's, it just invokes methods from project B and C.

Project B and C DLL reference's properties have Specific Version set to True.

I get the following warning during build:

"No way to resolve conflict between X and Y. Choosing Y arbitrarily".

As expected, only the project using the chosen DLL works properly. How do I force those projects to use those specific versions?

Jon Skeet
people
quotationmark

How do I force those projects to use those specific versions?

You can't, basically. Certainly not even close to easily. Even though Project A doesn't directly use the 3rd party DLLs, the CLR will still have to load them... at which point you've got an AppDomain with the following assemblies loaded:

  • ProjectA assembly
  • ProjectB assembly
  • ProjectC assembly
  • ThirdParty assembly, whichever version was picked

I don't think you can load multiple versions of the same assembly into the same AppDomain at a time.

Options:

  • You may be able to use separate AppDomains, one using project B and its version of the third party assembly, and one using project C and its version. In my experience, this sort of thing is very fiddly.
  • Fork the third party library (if it's open source) so you can build your own copy of it, with a different assembly name - use that for project B and let project C use the "normal" one
  • Change project B and C to use the same version

The last of these options is going to be the most maintainable by far, I suspect.

people

See more on this question at Stackoverflow