Skip to content

Instantly share code, notes, and snippets.

@chuongmep
Created May 11, 2023 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuongmep/8fa30b1f9ade9a5cf952c621e27376db to your computer and use it in GitHub Desktop.
Save chuongmep/8fa30b1f9ade9a5cf952c621e27376db to your computer and use it in GitHub Desktop.
string assPath = Assembly.GetExecutingAssembly().Location;
string? dirPath = Path.GetDirectoryName(Path.GetFullPath(assPath)) ?? null;
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
var assemblyName = new AssemblyName(args.Name);
if (!string.IsNullOrEmpty(dirPath))
{
var assemblyPath = Path.Combine(dirPath, assemblyName.Name + ".dll");
if (File.Exists(assemblyPath) == false) return null;
var assembly = Assembly.LoadFrom(assemblyPath);
return assembly;
}
return null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment