using System.Reflection;
using System.Runtime.Loader;
namespace Emby.Server.Implementations.Plugins;
///
/// A custom for loading Jellyfin plugins.
///
public class PluginLoadContext : AssemblyLoadContext
{
private readonly AssemblyDependencyResolver _resolver;
///
/// Initializes a new instance of the class.
///
/// The path of the plugin assembly.
public PluginLoadContext(string path) : base(true)
{
_resolver = new AssemblyDependencyResolver(path);
}
///
protected override Assembly? Load(AssemblyName assemblyName)
{
var assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
if (assemblyPath is not null)
{
return LoadFromAssemblyPath(assemblyPath);
}
return null;
}
}