Skip to content

Instantly share code, notes, and snippets.

@Rohansi
Last active October 11, 2015 11:46
Show Gist options
  • Save Rohansi/40770cc6663e04c3a76d to your computer and use it in GitHub Desktop.
Save Rohansi/40770cc6663e04c3a76d to your computer and use it in GitHub Desktop.
using System;
using System.Runtime.Loader;
using System.Reflection;
class CustomLoadContext : AssemblyLoadContext
{
protected override Assembly Load(AssemblyName assemblyName)
{
Console.WriteLine("loading {0}", assemblyName.Name);
return LoadFromAssemblyPath(string.Format(@"E:\Desktop\test-corerun\program\{0}.dll", assemblyName.Name));
}
}
public class Program
{
public static void Main(string[] args)
{
LoadAssembly();
Console.ReadLine();
}
public static void LoadAssembly()
{
var context = new CustomLoadContext();
var asm = context.LoadFromAssemblyName(new AssemblyName("Test"));
var type = asm.GetType("Test");
var method = type.GetMethod("DoSomething", BindingFlags.Public | BindingFlags.Static);
method.Invoke(null, null);
}
}
using System;
public static class Test
{
public static void DoSomething()
{
Console.WriteLine("hello world! {0}", TestDep.GetMessage());
}
}
using System;
public static class TestDep
{
public static string GetMessage()
{
return "snirt";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment