Edit

Share via


How to: Load and unload assemblies

The assemblies referenced by your program will automatically be loaded by the common language runtime, but it is also possible to dynamically load specific assemblies into the current application ___domain. For more information, see How to: Load assemblies into an application ___domain.

In .NET Framework, 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. In .NET Core, the System.Runtime.Loader.AssemblyLoadContext class handles the unloading of assemblies. For more information, see How to use and debug assembly unloadability in .NET Core.

Load and unload assemblies

To load an assembly into an application ___domain, use one of the several load methods contained in the classes AppDomain and Assembly. For more information, see How to: Load assemblies into an application ___domain. Note that .NET Core supports only a single application ___domain.

To unload an assembly in the .NET Framework, you must unload all of the application domains that contain it. To unload an application ___domain, use the AppDomain.Unload method. For more information, see How to: Unload an application ___domain.

If you want to unload some assemblies but not others in a .NET Framework application, 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.

See also