How to: Load and Unload Assemblies (C#)

The assemblies referenced by your program will automatically be loaded at build time, but it is also possible to load specific assemblies into the current application domain at runtime. For more information, see How to: Load Assemblies into an Application Domain.

There is no way to unload an individual assembly without unloading all of the application domains that contain it. Even if the assembly goes out of scope, the actual assembly file will remain loaded until all application domains that contain it are unloaded.

If you want to unload some assemblies but not others, consider creating a new application domain, executing the code inside that domain, and then unloading that application domain. For more information, see How to: Unload an Application Domain.

To load an assembly into an application domain

  1. Use one of the several load methods contained in the classes AppDomain and System.Reflection. For more information, see How to: Load Assemblies into an Application Domain.

To unload an application domain

  1. There is no way to unload an individual assembly without unloading all of the application domains that contain it. Use the Unload method from AppDomain to unload the application domains. For more information, see How to: Unload an Application Domain.

See Also

C# Programming Guide
Assemblies and the Global Assembly Cache (C#)
How to: Load Assemblies into an Application Domain