views:

18

answers:

0

Hello, i need to build a program that load older versions of a COM DLL file and performs some operations. I've created a DLL project for each version and set the reference to the correspondent COM. After that in the main program i'm trying to load the needed assembly that load and use itself its COM. The problem is that the DLLs have Interop files with the same name so i need to put each assembly (and COM file) in different folders. The generated interop assemblies has different classes within the same namespace. Example:

Version1.dll

namespace: ExternalCom

classes: A1, B1, C1

Version2.dll

namespace: ExternalCom

classes: A2, B2, C2

I've tried to use aliases to load each interop without conflits but with no success. Probably aliases doesn't work for COM files as for .NET files. So i've tried to load an assembly, use it and then unload everything from memory before using the next version. This has been done creating a new AppDomain, loading the assembly inside it and create an instance of my class from this last one:

AppDomainSetup setup = new AppDomainSetup();
setup.PrivateBinPath = @"\\L270"; // subfolder with my DLL, interop, isolated COM file

AppDomain domain = AppDomain.CreateDomain(type.ClassType, AppDomain.CurrentDomain.Evidence, setup);

domain.Load("L270"); // my assembly name

ObjectHandle oh = domain.CreateInstanceFrom(type.Filename, type.ClassType);
Object obj = oh.Unwrap();  

AppDomain.Unload(domain);

when i Unwrap the object it says it cannot load the interop. I've tried similar AppDomain creation, assembly loading functions and create instance ones but with similar errors. I've also tried to add an AssemblyResolve function to the AppDomain but the COM is not loaded.