Argh! Dynamic AppDomains and ApplicationPath headache.
I've been battling with the way the CLR handle AppDomains and loading assemblies for the last two days, and no success seems immanent. I need to load assemblies from two locations, my own ApplicationBase, and another directory, but I keep getting only one of them.
The issue is complicated because I'm trying to make NQA a multi AppDomain application, the reasoning is very simple, you can't unload a single assembly, only AppDomains, and the whole point of NQA is that you can load and unload assemblies and test them.
What I want to achieve is to load my own assembly and NHibernate to the dynamic AppDomain, and then load the user's assemblies. Then I can just call from the UI to the AppDomain and back. When the user recompile his assemblies, I can re-load the assemblies easily.
But I can't make it work!
I can either get the AppDomain to load my assembly and Nhibernate, or I can get it to load the user's assemblies (at least I think that I can, I can't test this until I can get the code to run!)
I've tried toying with ApplicationBase, PrivateBinPath, PrivateBinPathProbe, etc, with no success.
The scenario is really simple, I've the following directory structure:
C:\Directory One\main.exe, C:\Directory One\loader.dll, C:\Directory One\NHibernate.dll
C:\Directory Two\library.dll
What I want to do is, from main.exe, to create a new AppDomain, load loader.dll to it (which references NHibernate.dll) and then load library.dll from Directory Two.
I can't find a way to do this! If I set the ApplicationBase property of the AppDomain to Directory One, then the library.dll fails to load, if otherwise, then the loader.dll fails to load. If I try to use LoadFrom(), it fails because it can't find the referenced assemblies.
I can't assume that I've write access to either of those two directories, so just copying them there wouldn't work.
I'm going to experiment with AssemblyResolver and see if that can help me, but I'm not very optimistic.
Comments
Comment preview