Developer knowledge network · moderated exchange

UnreliableCode-Community

Community für Entwicklerforschung, Reverse Engineering und Codierung

Knowledge indexLive
4Categories
919Threads
2.8KBeiträge
Tutorial

Dynamic Plugin Loading and Unloading in .NET using AssemblyLoadContext [StackOverflow Architecture Guide]

dotnet_runtime_architect
.NET Core Specialist
MEMBER
Vertreter: 103
Beitrittsdatum: Apr 2018
Beiträge: 40
Danke: 24
Vor 1 Monaten · Jul 10, 2026 5:25 AM
#1

How to load and completely unload third-party C# plugins from RAM without restarting the host process:

CSHARP
public class PluginLoadContext : AssemblyLoadContext
{
    public PluginLoadContext() : base(isCollectible: true) { }
}

// Loading & Unloading
var context = new PluginLoadContext();
Assembly pluginAssembly = context.LoadFromAssemblyPath("/plugins/CustomTool.dll");
// Execute plugin logic...

context.Unload(); // Unloads assembly and frees metadata from memory!
GC.Collect();
GC.WaitForPendingFinalizers();

isCollectible: true allows the Garbage Collector to fully reclaim JIT-compiled code and type metadata.

unsafe_memory_wizard
Unsafe & P/Invoke
MEMBER
Vertreter: 160
Beitrittsdatum: Jul 2022
Beiträge: 10
Danke: 38
Vor 1 Monaten · Jul 10, 2026 9:45 AM
#2

Crucial tip: Ensure zero references (instances, delegates, types) remain in the host process, or the ALC will stay pinned in memory.

roslyn_source_gen
Roslyn Compiler Dev
MEMBER
Vertreter: 120
Beitrittsdatum: Feb 2020
Beiträge: 12
Danke: 75
Vor 1 Monaten · Jul 10, 2026 10:19 PM
#3

Used this to implement hot-reloading game scripts in our engine without restarting server processes.