Last active
October 11, 2015 11:46
-
-
Save Rohansi/40770cc6663e04c3a76d to your computer and use it in GitHub Desktop.
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
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); | |
} | |
} |
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
using System; | |
public static class Test | |
{ | |
public static void DoSomething() | |
{ | |
Console.WriteLine("hello world! {0}", TestDep.GetMessage()); | |
} | |
} |
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
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