none
How to unload assembly?

    Question

  • Hello,

    I'm now using Assembly class to load assemblies dynamically. However, I found there was no any method to unload the assembly. Because my application must delete the assembly file at some time, and if I loaded the assembly before I deleted it, I couldn't delete it because I had no authority to delete a file when it was using by my application.

    So, is there any method to unload the assembly?

    Thanks.

    Monday, March 24, 2008 2:49 PM

Answers

  • I don't know what is the purpose for unloading and deleting assembly in your case, but i give you a tip that you can rename every loaded assembly or exe file. I use this posibility to update my application assemblies, so when new version is available, i see which files are updated, rename all of the files, download new files with original names. Then on next app restart i delete all of renamed files, and application uses the new files.

    Monday, March 24, 2008 5:17 PM
  • It is not possible to unload an assembly. You can only unload an AppDomain. You could load your dynamic assemblies in a separate AppDomain, but then you have to cross AppDomains when calling methods in your assembly.

    If you're using .NET 3.5 (VS2008), you can use the addins (located in the namespace System.AddIns). This will take care of most of the problems when loading/unloading dynamic assemblies (add-ins).

    Monday, March 24, 2008 3:37 PM
  • The only way to unload an assembly is to unload the AppDomain into which it was loaded.  Most applications use only one AppDomain, so it is often not practical to unload arbitrary assemblies.

     

    It is possible to design your applications so that they have delineated "add-in" functionality that runs in separate AppDomains.  The .NET 3.5 features in the System.AddIn namespace can help with this.  http://msdn2.microsoft.com/en-us/magazine/cc163476.aspx

     

    Monday, March 24, 2008 3:44 PM

All replies

  • It is not possible to unload an assembly. You can only unload an AppDomain. You could load your dynamic assemblies in a separate AppDomain, but then you have to cross AppDomains when calling methods in your assembly.

    If you're using .NET 3.5 (VS2008), you can use the addins (located in the namespace System.AddIns). This will take care of most of the problems when loading/unloading dynamic assemblies (add-ins).

    Monday, March 24, 2008 3:37 PM
  • The only way to unload an assembly is to unload the AppDomain into which it was loaded.  Most applications use only one AppDomain, so it is often not practical to unload arbitrary assemblies.

     

    It is possible to design your applications so that they have delineated "add-in" functionality that runs in separate AppDomains.  The .NET 3.5 features in the System.AddIn namespace can help with this.  http://msdn2.microsoft.com/en-us/magazine/cc163476.aspx

     

    Monday, March 24, 2008 3:44 PM
  • I don't know what is the purpose for unloading and deleting assembly in your case, but i give you a tip that you can rename every loaded assembly or exe file. I use this posibility to update my application assemblies, so when new version is available, i see which files are updated, rename all of the files, download new files with original names. Then on next app restart i delete all of renamed files, and application uses the new files.

    Monday, March 24, 2008 5:17 PM