diff options
| author | Patrick Barron <barronpm@gmail.com> | 2023-01-15 17:00:38 -0500 |
|---|---|---|
| committer | Patrick Barron <barronpm@gmail.com> | 2023-01-15 17:00:38 -0500 |
| commit | a48f18887468015876a8b056f15b68d6ef49ce04 (patch) | |
| tree | 6851299f6cf76890ea33111cd9281f1a0fe1c13f | |
| parent | dc85d86ea1db7608368eadbfee80f7618653f42d (diff) | |
Use separate assembly load contexts per plugin
| -rw-r--r-- | Emby.Server.Implementations/Plugins/PluginManager.cs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index 6ef66f2b5..3be20e7e3 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -31,7 +31,7 @@ namespace Emby.Server.Implementations.Plugins { private readonly string _pluginsPath; private readonly Version _appVersion; - private readonly AssemblyLoadContext _assemblyLoadContext; + private readonly List<AssemblyLoadContext> _assemblyLoadContexts; private readonly JsonSerializerOptions _jsonOptions; private readonly ILogger<PluginManager> _logger; private readonly IApplicationHost _appHost; @@ -79,7 +79,7 @@ namespace Emby.Server.Implementations.Plugins _minimumVersion = new Version(0, 0, 0, 1); _plugins = Directory.Exists(_pluginsPath) ? DiscoverPlugins().ToList() : new List<LocalPlugin>(); - _assemblyLoadContext = new AssemblyLoadContext("PluginContext", true); + _assemblyLoadContexts = new List<AssemblyLoadContext>(); } private IHttpClientFactory HttpClientFactory @@ -128,7 +128,10 @@ namespace Emby.Server.Implementations.Plugins Assembly assembly; try { - assembly = _assemblyLoadContext.LoadFromAssemblyPath(file); + var assemblyLoadContext = new AssemblyLoadContext($"{plugin.Name} ${plugin.Version}", true); + _assemblyLoadContexts.Add(assemblyLoadContext); + + assembly = assemblyLoadContext.LoadFromAssemblyPath(file); // Load all required types to verify that the plugin will load assembly.GetTypes(); @@ -163,7 +166,10 @@ namespace Emby.Server.Implementations.Plugins /// <inheritdoc /> public void UnloadAssemblies() { - _assemblyLoadContext.Unload(); + foreach (var assemblyLoadContext in _assemblyLoadContexts) + { + assemblyLoadContext.Unload(); + } } /// <summary> |
