This commit is contained in:
🎧 RicherTunes 🎧 2026-04-19 17:40:46 +01:00 committed by GitHub
commit 021b147fdc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,6 +12,7 @@ namespace NzbDrone.Common.Composition
public static class PluginLoader
{
private static readonly Logger Logger = NzbDroneLogger.GetLogger(typeof(PluginLoader));
private static readonly List<PluginLoadContext> PluginContexts = new ();
public static (List<Assembly>, List<WeakReference>) LoadPlugins(IEnumerable<string> pluginPaths)
{
@ -38,6 +39,7 @@ public static bool UnloadPlugins(List<WeakReference> pluginRefs)
private static (Assembly, WeakReference) LoadPlugin(string path)
{
var context = new PluginLoadContext(path);
PluginContexts.Add(context);
var weakRef = new WeakReference(context, trackResurrection: true);
// load from stream to avoid locking on windows
@ -53,7 +55,9 @@ private static void RequestPluginUnload(List<WeakReference> pluginRefs)
{
if (pluginRef?.Target != null)
{
((PluginLoadContext)pluginRef.Target).Unload();
var context = (PluginLoadContext)pluginRef.Target;
PluginContexts.Remove(context);
context.Unload();
}
}
}