Developer knowledge network ยท moderated exchange

Onbetrouwbare Code-gemeenschap

Ontwikkelaarsonderzoek, reverse engineering en coderingsgemeenschap

Knowledge indexLive
4Categories
919Threads
2.8KBerichten
Tutorial

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

dotnet_runtime_architect
.NET Core Specialist
MEMBER
Vertegenwoordiger: 103
Datum van deelname: Apr 2018
Berichten: 40
Bedankt: 24
1 maanden geleden ยท 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
Vertegenwoordiger: 160
Datum van deelname: Jul 2022
Berichten: 10
Bedankt: 38
1 maanden geleden ยท 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
Vertegenwoordiger: 120
Datum van deelname: Feb 2020
Berichten: 12
Bedankt: 75
1 maanden geleden ยท Jul 10, 2026 10:19 PM
#3

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