Created
July 4, 2022 17:34
-
-
Save TsuyoshiUshio/551cb0f71c704aca75209552af50fc7a to your computer and use it in GitHub Desktop.
PluginLoadContext
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PluginLoadContext : AssemblyLoadContext | |
{ | |
private AssemblyDependencyResolver _resolver; | |
public PluginLoadContext(string pluginPath) | |
{ | |
_resolver = new AssemblyDependencyResolver(pluginPath); | |
} | |
protected override Assembly? Load(AssemblyName assemblyName) | |
{ | |
string assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName); | |
if (assemblyPath != null) | |
{ | |
return LoadFromAssemblyPath(assemblyPath); | |
} | |
return null; | |
} | |
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName) | |
{ | |
string libraryPath = _resolver.ResolveUnmanagedDllToPath(unmanagedDllName); | |
if (libraryPath != null) | |
{ | |
return LoadUnmanagedDllFromPath(libraryPath); | |
} | |
return IntPtr.Zero; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment