I would like to unload a custom AppDomain and afterwards delete an assembly (from harddisk) which was loaded inside this AppDomain. I found a lot of resources suggesting to load the assembly via Assembly.Load(byte[]). Doing this makes it possible to delete the file, however, my code does not use this loaded assembly.
Basically I have two assemblies: A.dll and B.dll
A.dll references B.dll and wants to call into B.dll.
In my custom AppDomain I load both A.dll and B.dll via Assembly.LoadFrom. Then I invoke a method in A and it automatically calls into the loaded B.
The difficulty is that in the global AppDomain both A and B are already loaded, however, the version of B.dll loaded in the global AppDomain is not the same as the one I wish to load in the custom AppDomain.
Using the Assembly.LoadFrom method makes A call the correct version of B
Using the Assembly.Load(byte[]) method makes A call the version of B which is in the global AppDomain.
What I want is that either: loading A.dll as byte[] and B references it correctly, or loading A.dll with Assembly.LoadFrom but being able to delete it after unloading the AppDomain.
Has anyone an idea of how to achieve this?
Thanks, Christian