How to load and completely unload third-party C# plugins from RAM without restarting the host process:
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.