Using different dependencies depending on the instance of a class in C #

Like this:

  • I have 2 SDK libraries provided by 2 different companies (dlls).
  • Both used the same 3rd party DLL as dependencies for these SDKs
  • The DLL versions used by each company are different.
  • My code needs to instantiate one of the DLLs based on user input. It will never be necessary to instantiate both in the same mode.
  • There is no way to ask a company to use the same version of a third party DLL.

Now I am removing the dependency and compiling the code 2 times. And forcing the user to choose the installation time to use.

I wanted to check if this is possible:

  • (best of all) for dynamically loading a runtime dependency - depending on the instance of the class. or if this is not possible:
  • include a compile-time directive to select the correct dependencies

Note that the problematic dll is a second level dependency required for a level 1 dependency. So I probably need dynamic loading (think)

+3


source to share


1 answer


If the shared third party dll is heavily signed and the later version is compatible with the previous one, you can use the assembly redirection policy in the .config file to always use the latest version.

those. works great with Json.Net libraries (strongly signed, later versions can be used instead of earlier ones)



Example from the article:

 <dependentAssembly>
    <assemblyIdentity name="someAssembly" publicKeyToken="32ab4ba45e0a69a1"/>
    <bindingRedirect oldVersion="7.0.0.0" newVersion="8.0.0.0" />
  </dependentAssembly>

      

0


source







All Articles