static void Main(string[] args) { Console.WriteLine("Hello plugins! -see memory in task manager"); string PluginBPath = Path.Combine(Environment.CurrentDirectory, "pluginB"); Console.ReadKey(); LoadAssemblyA(); Console.WriteLine("start collect after unload"); for (int i = 0; i < 10; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); Thread.Sleep(1000); } Console.WriteLine("after unload"); Console.ReadKey(); { var tcB = new TestAssemblyLoadContext(PluginBPath); tcB.GetMyPlugin().LoadData(); tcB.Unload(); } for (int i = 0; i < 10; i++) { GC.Collect(); GC.WaitForPendingFinalizers(); Thread.Sleep(1000); } Console.ReadKey(); }
static void LoadAssemblyA() { string PluginAPath = Path.Combine(Environment.CurrentDirectory, "pluginA"); //Ensure that you have copied the pluginA and pluginB var tcA = new TestAssemblyLoadContext(PluginAPath); var s = tcA.GetMyPlugin(); s.LoadData(); Console.WriteLine("before unload -see task manager memory"); Console.ReadKey(); tcA.Unload(); }
static void Main(string[] args) { Console.WriteLine("Hello plugins!"); string PluginAPath = Path.Combine(Environment.CurrentDirectory, "pluginA"); string PluginBPath = Path.Combine(Environment.CurrentDirectory, "pluginB"); var tcA = new TestAssemblyLoadContext(PluginAPath); tcA.GetMyPlugin().LoadData(); tcA.Unload(); var tcB = new TestAssemblyLoadContext(PluginBPath); tcB.GetMyPlugin().LoadData(); tcB.Unload(); }