31 lines
1.0 KiB
C#
31 lines
1.0 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using System.Runtime.Loader;
|
|
using Microsoft.Extensions.DependencyModel;
|
|
using Props.Shop.Framework;
|
|
|
|
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)
|
|
{
|
|
if (assemblyName.FullName.Equals(typeof(IShop).Assembly.FullName)) return null;
|
|
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;
|
|
}
|
|
}
|
|
} |