Unload DLL after loading with Assembly.LoadFrom()
In my project I am loading a DLL using reflection and As开发者_高级运维sembly.LoadFrom()
. This is a small DLL that is occasionally recompiled (from the source) dynamically during application execution.
Is there a way to unload the loaded DLL from the application so that I can reload it? I've tried reloading it, but I get an error:
file in use by another program
If the application that has the file open is a custom app, then you could modify it to load the DLL into another AppDomain. When you want to reload it, simply tear down that AppDomain and load the new DLL into the new AppDomain. I'd have a look at MEF (which does this) to see whether this might support your use case.
You can't. You have to kill the program. There is no way to unload an assembly in .Net.
Read these:
http://blogs.msdn.com/b/jasonz/archive/2004/05/31/145105.aspx
http://blogs.msdn.com/b/suzcook/archive/2003/07/08/unloading-an-assembly.aspx
精彩评论