props/Props/Services/Modules/ShopAssemblyLoadContext.cs

29 lines
933 B
C#
Raw Normal View History

using System;
using System.Reflection;
using System.Runtime.Loader;
using Microsoft.Extensions.DependencyModel;
namespace Props.Services.Modules
{
internal class ShopAssemblyLoadContext : AssemblyLoadContext
{
private AssemblyDependencyResolver resolver;
public ShopAssemblyLoadContext(string path)
{
resolver = new AssemblyDependencyResolver(path);
}
protected override Assembly Load(AssemblyName assemblyName)
{
string assemblyPath = resolver.ResolveAssemblyToPath(assemblyName);
return assemblyPath != null ? LoadFromAssemblyPath(assemblyPath) : null;
}
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
{
string libPath = resolver.ResolveUnmanagedDllToPath(unmanagedDllName);
return libPath != null ? LoadUnmanagedDllFromPath(libPath) : IntPtr.Zero;
}
}
}