views:

302

answers:

2

Hi,

I would like to load two different versions of the same dll within the same process. At the same time I would like to avoid placing any of them in the GAC.

Any ideas?

Thanks, Krikor

A: 

Activator.CreateInstance. Check msdn for examples.

No Refunds No Returns
Thanks for the answer but I am trying to avoid reflection as well. All I want to do is force the framework to resolve to the correct file. I have tons of different types in that dll and using reflection would be costly to implement.
Krikor
You're going to have to load the DLLs yourself anyway using Load... Methods. Compared to the IO to do that the reflection will be insignificant. Reflection has a "bad" reputation because most people never measure it. Avoid where possible, yes but don't shun completely when it's the right answer.
No Refunds No Returns
A: 

Yes, it seems like i have to manually load the assembly, one way or another.

One solution that i found was to subscribe to the AssemblyResolve event of the appDomain. This event is raised when an assembly is not found and allows you to manually provide it.

  1. Reregister an event handler like this

AppDomain.CurrentDomain.AssemblyResolve += MyResolveEventHandler;

static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) { return Assembly.LoadFrom(@"OldAsm\Asm.dll"); }

  1. Once the code that uses the specific code is reached the .NET Framework will try to load the assembly, it will crash and will call your handler (MyResolveEventHandler).

I would keep looking for a way to resolve the right reference without having to write any code and without having to put anything in the GAC. If anyone finds a way, please post it.

Thanks

Krikor