-1

I am writing a wrapper for a library that got a drastic change in the API between one version and the other, so I need to create a contract that will allow me to access the two versions of the same API. This is my project structure:

- Client.dll
  - References
    - Contract.dll
    - Version01.dll
    - Version02.dll
- Contract.dll
  - IMyService.cs
- Version01.dll
  - MyServiceImplementation.cs
  - References
    - Version01Assembly.dll
- Version02.dll
  - MyServiceImplementation.cs
  - References
    - Version02Assembly.dll

Inside the Project Client.dll I may need to call one implementation of the service or another one, and this is quite fine. The issue is that the assembly loaded into the AppDomain is always the Version02Assembly.dll cause in the bin folder of my Client I always find only the latest version of this dependency. How can I keep these two libraries referencing a different version of the same assembly?

I hope the question is clear

Devolus
  • 21,661
  • 13
  • 66
  • 113
Raffaeu
  • 6,694
  • 13
  • 68
  • 110
  • you want to refer two versions of an assembly in a project? – NoviceProgrammer Feb 18 '14 at 08:53
  • No, look at the project structure. It's a dependency that has a reference to an external assembly. Two version using two different dependencies versions – Raffaeu Feb 18 '14 at 08:55
  • Possible duplicate of [Need a way to reference 2 different versions of the same 3rd party DLL](https://stackoverflow.com/questions/11550981/need-a-way-to-reference-2-different-versions-of-the-same-3rd-party-dll) – Orace Nov 20 '19 at 11:15

1 Answers1

0

I haven't ever done it but I think you have two choices -

  1. If possible, give strong names to these assemblies and move them to GAC.

  2. If (1) is not possible, move the assemblies into sub-folders (v1.x & v2.x). Then load the assembly using Assembly.LoadFrom() or AppDomain.Load [ it is possible you might run into type resolution issues, so please read through - http://msdn.microsoft.com/en-us/library/dd153782.aspx#avoid_loading_multiple_versions ]

NoviceProgrammer
  • 3,347
  • 1
  • 22
  • 32
  • I can't give them a strong name cause they are external libraries, but they completely changed the API from v1 to v2 and we need to provide access to both libraries from our app. One connect to TFS 2008 and one to TFS 2012/13. I will move the assemblies into different folders and use the Assembly load method to load the dependencies. – Raffaeu Feb 18 '14 at 09:20