Reputation: 1854
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?
Upvotes: 4
Views: 3279
Reputation: 12550
Once an assembly is loaded into an AppDomain
, it does not (cannot) get unloaded until the AppDomain
is 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
which you can then load your assembly into....when you are finished you just call Unload
to shutdown the AppDomain
and this will release the assembly.
However the types you want to be accessible from the other AppDomains
have to derive from MarshalByRefObject
so that your object is remoteable....and calls from other AppDomains can be marshalled across.
A very interesting technique here....it loads the assembly into a MemoryStream
first, then it gets .NET to load the Assembly from the MemoryStream
...that means the "file" on disk, isn't locked.
Upvotes: 6