aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/Plugins/PluginLoadContext.cs
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2023-01-17 21:11:32 +0100
committerGitHub <noreply@github.com>2023-01-17 21:11:32 +0100
commit212876b23562f9cf1f5ce7a415f7187d45712c79 (patch)
treea3f613b241891562516280cc226da73f510eb940 /Emby.Server.Implementations/Plugins/PluginLoadContext.cs
parent70a74a8c62d889d2e186fd2a3a27263b4beab3c4 (diff)
parentc59f2a3c46dd3fad42dd987e04e48d6576373b13 (diff)
Merge pull request #9100 from barronpm/refactor-startup
Diffstat (limited to 'Emby.Server.Implementations/Plugins/PluginLoadContext.cs')
-rw-r--r--Emby.Server.Implementations/Plugins/PluginLoadContext.cs33
1 files changed, 33 insertions, 0 deletions
diff --git a/Emby.Server.Implementations/Plugins/PluginLoadContext.cs b/Emby.Server.Implementations/Plugins/PluginLoadContext.cs
new file mode 100644
index 000000000..d04e9cf68
--- /dev/null
+++ b/Emby.Server.Implementations/Plugins/PluginLoadContext.cs
@@ -0,0 +1,33 @@
+using System.Reflection;
+using System.Runtime.Loader;
+
+namespace Emby.Server.Implementations.Plugins;
+
+/// <summary>
+/// A custom <see cref="AssemblyLoadContext"/> for loading Jellyfin plugins.
+/// </summary>
+public class PluginLoadContext : AssemblyLoadContext
+{
+ private readonly AssemblyDependencyResolver _resolver;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="PluginLoadContext"/> class.
+ /// </summary>
+ /// <param name="path">The path of the plugin assembly.</param>
+ public PluginLoadContext(string path) : base(true)
+ {
+ _resolver = new AssemblyDependencyResolver(path);
+ }
+
+ /// <inheritdoc />
+ protected override Assembly? Load(AssemblyName assemblyName)
+ {
+ var assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
+ if (assemblyPath is not null)
+ {
+ return LoadFromAssemblyPath(assemblyPath);
+ }
+
+ return null;
+ }
+}