I have an application that loads a DLL to execute a specific part of processing
Example : \"Application.dll\" loading \"Process.dll\"
Once an assembly has been loaded into an AppDomain
, it cannot be unloaded. You have to dispose of the AppDomain
. If you need to load and unload assemblies within an application, you'll need to spawn a new AppDomain
and load the assembly, then destroy the AppDomain
once you're finished with the assembly.
While you seem to solve the problem according to your edit here are couple comments:
Watch out for objects from your Process.dll "leaking" into main AppDomain. I.e. something like throwing custom exception defined in Process.dll and caught in main AppDomain will force Process.dll to be loaded into main AppDomain. Check list of loaded assemblies in the main AppDomain after performing operations you are interested in.
Unloading of AppDomain can fail and may take long time.
It's been quite a while since I looked at this but I'm fairly sure that you'd need to create a new AppDomain and then load the DLL inside there.
The reason is that you can't unload an Assembly
by it self but you can unload an AppDomain
that contains an Assembly
.
Here's a CodeProject article that describes how to do this: To Unload a Running Dll