Skip to content

Instantly share code, notes, and snippets.

@TsuyoshiUshio
Created March 17, 2022 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save TsuyoshiUshio/29f930aa267ff8bea292715467b0f40a to your computer and use it in GitHub Desktop.
Save TsuyoshiUshio/29f930aa267ff8bea292715467b0f40a to your computer and use it in GitHub Desktop.
AssemblyLoadContext Sample
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