How Can I Unload an Assembly?
-
I can successfully load an assembly dynamically at runtime. But what if I want to unload it and load another one without having to shutdown my application. Does anyone know how to do that? I use Activator.CreateInstance to load assemblies. But I have not found anything that I can use to unload one.
-
I can successfully load an assembly dynamically at runtime. But what if I want to unload it and load another one without having to shutdown my application. Does anyone know how to do that? I use Activator.CreateInstance to load assemblies. But I have not found anything that I can use to unload one.
Assemblies are loaded into an AppDomain when you Type they define is required. You cannot unload assemblies from an AppDomain without shutting down the AppDomain (closing/killing the process is one way of doing this).
Microsoft MVP, Visual C# My Articles
-
I can successfully load an assembly dynamically at runtime. But what if I want to unload it and load another one without having to shutdown my application. Does anyone know how to do that? I use Activator.CreateInstance to load assemblies. But I have not found anything that I can use to unload one.
Similar to what Heath said, but you can create your own AppDomain's and load the assemblies into there. Then, when you want to unload the assembly, destroy the AppDomain. I think there's some article on MSDN about doing that. Marc Microsoft MVP, Visual C# MyXaml MyXaml Blog
-
Similar to what Heath said, but you can create your own AppDomain's and load the assemblies into there. Then, when you want to unload the assembly, destroy the AppDomain. I think there's some article on MSDN about doing that. Marc Microsoft MVP, Visual C# MyXaml MyXaml Blog
Well I did try following that example and it worked up to a point. I get Serialization exceptions because .NET is trying to serialize System.Threading.Thread and other System classes. I can only modify my own classes to meed serialization requirements. What do I do about the System classes I need objects of sever System types in the assembly that I am trying to load into a separate AppDomain. For more than 2 years I did not have any such issue because I was loading assemblies into the default AppDomain. But I now have a need to dynamically load and unload them. Do you know of a solutions that will not try to serialize System classes. I can only modify my classes with MarshalByRefObject or [Serializable]. Thanks Robert