Is there a way with a plugin system (I would use with an IoC container) to load one version of an assembly at runtime and then replace that DLL while the AppDomain is running? I don't want to restart the application.
Does MEF do something like this?
Is there a way with a plugin system (I would use with an IoC container) to load one version of an assembly at runtime and then replace that DLL while the AppDomain is running? I don't want to restart the application.
Does MEF do something like this?
This is essentially what NUnit does (or at least did, I haven't been in the code in a while). But it does it by loading the test assembly in another AppDomain, calling code in that domain using the DoCallback method of AppDomain and then reloads the test assembly if it is recompiled.
So while you can't unload or reload a dll, but you can unload and reload an appdomain and execute code in it.
It is impossible using pure .net, because there is no way to unload assembly from domain. Since MEF is written in managed code I doubt that it is possible. I solved this issue by loading assembly to separate domain and when I wanted to reload it I stoped it and started again.
You cannot unload dll in a running app domain. What you can do is use MEF and prepare your app to handle multiple implementations. In that case, you can copy a new dll (a new implementaion of an interface, module, etc.) into the MEF folder, recompose and use it. But, careful, it is gonna cost you memory.
You can read about it and download sample here.
It looks like this CodeProject article explains how to do it. This question on the MSDN Forums seems similiar and this SO question shows how to do it. All of these links warn of leaks being created by problems disposing AppDomains properly, so buyer beware.