-
-
Save TsuyoshiUshio/29f930aa267ff8bea292715467b0f40a to your computer and use it in GitHub Desktop.
AssemblyLoadContext Sample
This file contains 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