Use custom plugin assembly load context
This commit is contained in:
parent
a48f188874
commit
577d396649
33
Emby.Server.Implementations/Plugins/PluginLoadContext.cs
Normal file
33
Emby.Server.Implementations/Plugins/PluginLoadContext.cs
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -128,7 +128,7 @@ namespace Emby.Server.Implementations.Plugins
|
||||||
Assembly assembly;
|
Assembly assembly;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var assemblyLoadContext = new AssemblyLoadContext($"{plugin.Name} ${plugin.Version}", true);
|
var assemblyLoadContext = new PluginLoadContext(file);
|
||||||
_assemblyLoadContexts.Add(assemblyLoadContext);
|
_assemblyLoadContexts.Add(assemblyLoadContext);
|
||||||
|
|
||||||
assembly = assemblyLoadContext.LoadFromAssemblyPath(file);
|
assembly = assemblyLoadContext.LoadFromAssemblyPath(file);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user