LoadDll/加载dll/加载插件上下文.cs

46 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Loader;
using System.Text;
using System.Threading.Tasks;
using Dll;
namespace dll
{
class : AssemblyLoadContext
{
private AssemblyDependencyResolver? _解析器;
public (string )
{
_解析器 = new AssemblyDependencyResolver();
}
protected override Assembly? Load(AssemblyName )
{
string? = _解析器?.ResolveAssemblyToPath();
if ( != null)
{
return LoadFromAssemblyPath();//从路径加载程序集
}
return null;
}
protected override IntPtr LoadUnmanagedDll(string DLL名称)//重写加载非托管DLL方法
{
string? libraryPath = _解析器?.ResolveUnmanagedDllToPath(DLL名称);//解析非托管类型DLL为路径
if (libraryPath != null)
{
return LoadUnmanagedDllFromPath(libraryPath);//从路径加载程序集
}
return IntPtr.Zero;
}
}
}