Using Prism with WPF, I want to allow users to select from a repository which modules they’d like to use. Each module is essentially an add-on, and selecting a module to use would just move it into their ‘Modules’ folder of DLL to load.
But, in trying to move DLLs around when the application is running, an error is thrown because the DLLs are in use at that moment. How can you get around this and allow users to Add/Remove modules at will?
Once an assembly is loaded into an
AppDomain, it does not (cannot) get unloaded until theAppDomainis torn down….I guess that is your problem.There’s some techniques to get around that if you look on the net…..
Create An Additional AppDomain
Create an additional
AppDomainwhich you can then load your assembly into….when you are finished you just callUnloadto shutdown theAppDomainand this will release the assembly.However the types you want to be accessible from the other
AppDomainshave to derive fromMarshalByRefObjectso that your object is remoteable….and calls from other AppDomains can be marshalled across.Load Assembly into a MemoryStream
A very interesting technique here….it loads the assembly into a
MemoryStreamfirst, then it gets .NET to load the Assembly from theMemoryStream…that means the “file” on disk, isn’t locked.http://social.msdn.microsoft.com/Forums/en-US/clr/thread/093c3606-e68e-46f4-98a1-f2396d3f88ca/
How do I implement .net plugins without using AppDomains?