aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Plugins/PluginManager.cs
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2023-01-19 10:09:32 +0100
committerShadowghost <Ghost_of_Stone@web.de>2023-01-19 10:09:32 +0100
commit656a0bff6fd48ba66cfe8fc7b470380c38afbac2 (patch)
treea89f0545050bf6672936c6e7ea3e2b0e5c5561f2 /Emby.Server.Implementations/Plugins/PluginManager.cs
parentef085483b2ef54195e16f282330a3c204e3227b6 (diff)
parentd57dcf22452db4990aa2cdece3eb798ba98b8330 (diff)
Merge remote-tracking branch 'upstream/master' into network-rewrite
Diffstat (limited to 'Emby.Server.Implementations/Plugins/PluginManager.cs')
-rw-r--r--Emby.Server.Implementations/Plugins/PluginManager.cs18
1 files changed, 17 insertions, 1 deletions
diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs
index 14e7c2269..f2212f4dc 100644
--- a/Emby.Server.Implementations/Plugins/PluginManager.cs
+++ b/Emby.Server.Implementations/Plugins/PluginManager.cs
@@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
+using System.Runtime.Loader;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
@@ -30,6 +31,7 @@ namespace Emby.Server.Implementations.Plugins
{
private readonly string _pluginsPath;
private readonly Version _appVersion;
+ private readonly List<AssemblyLoadContext> _assemblyLoadContexts;
private readonly JsonSerializerOptions _jsonOptions;
private readonly ILogger<PluginManager> _logger;
private readonly IApplicationHost _appHost;
@@ -76,6 +78,8 @@ namespace Emby.Server.Implementations.Plugins
_appHost = appHost;
_minimumVersion = new Version(0, 0, 0, 1);
_plugins = Directory.Exists(_pluginsPath) ? DiscoverPlugins().ToList() : new List<LocalPlugin>();
+
+ _assemblyLoadContexts = new List<AssemblyLoadContext>();
}
private IHttpClientFactory HttpClientFactory
@@ -124,7 +128,10 @@ namespace Emby.Server.Implementations.Plugins
Assembly assembly;
try
{
- assembly = Assembly.LoadFrom(file);
+ var assemblyLoadContext = new PluginLoadContext(file);
+ _assemblyLoadContexts.Add(assemblyLoadContext);
+
+ assembly = assemblyLoadContext.LoadFromAssemblyPath(file);
// Load all required types to verify that the plugin will load
assembly.GetTypes();
@@ -156,6 +163,15 @@ namespace Emby.Server.Implementations.Plugins
}
}
+ /// <inheritdoc />
+ public void UnloadAssemblies()
+ {
+ foreach (var assemblyLoadContext in _assemblyLoadContexts)
+ {
+ assemblyLoadContext.Unload();
+ }
+ }
+
/// <summary>
/// Creates all the plugin instances.
/// </summary>