Unload Dynamic Assembly
-
Saturday, June 09, 2012 8:22 AM
Hi I use System.AppDomain.DefineDynamicAssembly generated a dynamic assemly. How can I unload the assembly?
Let me clarify this little bit more. I know that assemblies can not be unloaded except it's being loaded in a separate appdomain. According to this aritcle http://msdn.microsoft.com/en-us/library/dd554932.aspx (Collectible Assemblies for Dynamic Type Generation)
"
To enable unloading, use the AssemblyBuilderAccess.RunAndCollect flag when you create a dynamic assembly. The assembly is transient (that is, it cannot be saved) and is subject to limitations described in the Restrictions on Collectible Assemblies section. The common language runtime (CLR) unloads a collectible assembly automatically when you have released all objects associated with the assembly. In all other respects, collectible assemblies are created and used in the same way as other dynamic assemblies.
"
I wonder if there is any way that you could explicitly unload the assembly
Regards
John Huang, MVP-SQL, MCM-SQL, http://www.sqlnotes.info
- Edited by John-HuangMVP Saturday, June 09, 2012 9:01 AM
All Replies
-
Saturday, June 09, 2012 8:59 AM
Hi,
We cannot unload loaded assembly alone the only way is unload AppDomain.
(http://msdn.microsoft.com/en-us/library/ms173101(v=VS.80).aspx)
If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
-
Saturday, June 09, 2012 8:59 AM
Let me clarify this little bit more. I know that assemblies can not be unloaded except it's being loaded in a separate appdomain. According to this aritcle http://msdn.microsoft.com/en-us/library/dd554932.aspx (Collectible Assemblies for Dynamic Type Generation)
"
To enable unloading, use the AssemblyBuilderAccess.RunAndCollect flag when you create a dynamic assembly. The assembly is transient (that is, it cannot be saved) and is subject to limitations described in the Restrictions on Collectible Assemblies section. The common language runtime (CLR) unloads a collectible assembly automatically when you have released all objects associated with the assembly. In all other respects, collectible assemblies are created and used in the same way as other dynamic assemblies.
"
I wonder if there is any way that you could explicitly unload the assembly
Regards
-
Saturday, June 09, 2012 9:00 AMThanks for your response, i just clarified my questions there.
Regards
-
Tuesday, August 07, 2012 10:07 AM
Let me clarify this little bit more. I know that assemblies can not be unloaded except it's being loaded in a separate appdomain. According to this aritcle http://msdn.microsoft.com/en-us/library/dd554932.aspx (Collectible Assemblies for Dynamic Type Generation)
"
To enable unloading, use the AssemblyBuilderAccess.RunAndCollect flag when you create a dynamic assembly. The assembly is transient (that is, it cannot be saved) and is subject to limitations described in the Restrictions on Collectible Assemblies section. The common language runtime (CLR) unloads a collectible assembly automatically when you have released all objects associated with the assembly. In all other respects, collectible assemblies are created and used in the same way as other dynamic assemblies.
"
I wonder if there is any way that you could explicitly unload the assembly
Regards
Hello,
Term "unloads a collectible assembly automatically" the assembly will unloaded "asynchronously" so if you "explicitly" relase reference of types of assembly it will be unloaded. By mean of "need explicity unload", Do u want to wait this happens and block your code or you need critical time that the assembly must be unloaded ASAP?
Regards.

