0

This is a follow-up to a previous question Is it possible to switch DLLs at runtime so as to use a different version?.

Since posting that question I have reorganised my project but am still have DLL loading problems.

I have 3 main projects: the application, a library containing MEF plugins and a second library containing more MEF plugins. Each plugin handles a type of IO device.

The manufacturer of one of the devices has produced a new set of identically named but incompatible DLLs. I now have 2 plugins to handle each version and put them in 2 separate projects (MEF Lib1 & MEF Lib2).

The MEF loader decides which one of the conflicting plugins to load (only one is needed) and the plugin is told to initialise itself. It then copies its' DLLs (managed and unmanaged) to the execution folder before the DLLs are accessed.

This does not work as desired. The managed DLLs are correct but the unmanaged DLL that actually gets loaded is an older version.

I have tried using the AppDomain.AssemblyResolve event but this only seems to be activated when a DLL cannot be found. In my case, the DLL is always found - just not the one I want.

What am I doing wrong?

Community
  • 1
  • 1
paul
  • 13,312
  • 23
  • 81
  • 144
  • 2
    All of the Reflection stuff in the Framework (including AppDomain.AssemblyResolve) will only work with managed assemblies. You need to make sure that each managed assembly is pointing properly to the correct unmanaged DLL. Note that COM registration could be a complicating factor. – Robert Harvey May 05 '15 at 05:33
  • @RobertHarvey - *'You need to make sure that each managed assembly is pointing properly to the correct unmanaged DLL'* How would I do that? – paul May 05 '15 at 05:42
  • Since these are unmanaged DLLs, do you have a wrapper class that calls the functions and methods of the DLL? – Bernd Linde May 05 '15 at 06:01
  • @BerndLinde - the DLLs come as a package from the manufacturer. I just access the managed DLLs in the usual way. The unmanaged DLLs are pickup by the managed DLL and I have no influence over that - except to ensure that they are available – paul May 05 '15 at 07:16
  • To ensure that no residual DLLs are in your GAC, use the [ProcMon](https://technet.microsoft.com/en-gb/sysinternals/bb896645.aspx) application to check where the unmanaged DLL is accessed from. I agree with your theory that is should grab the one in the local folder, so somewhere there is an old version that needs to be removed first – Bernd Linde May 05 '15 at 07:27

0 Answers0