WPF Prism - Manage Modules In Application

依然范特西╮ 提交于 2019-12-21 17:58:06

问题


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?


回答1:


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

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.

  • Using AppDomain in C# to dynamically load and unload dll

Load Assembly into a MemoryStream

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.

  • http://social.msdn.microsoft.com/Forums/en-US/clr/thread/093c3606-e68e-46f4-98a1-f2396d3f88ca/

  • How do I implement .net plugins without using AppDomains?



来源:https://stackoverflow.com/questions/12898269/wpf-prism-manage-modules-in-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!