protected override Assembly Load(AssemblyName assemblyName)
        {
            if (assemblyName.Name == "Dahomey.Json")
            {
                TestLoadContext tlc = new TestLoadContext(assemblyName.ToString());

                Program.AddContext(tlc);

                return(tlc.LoadFromAssemblyPath(Path.GetFullPath("Dahomey.Json.dll")));
            }

            return(base.Load(assemblyName));
        }
Exemple #2
0
        static void CallJson()
        {
            TestLoadContext tlc = new TestLoadContext("LibraryLoaded");

            var asm = tlc.LoadFromAssemblyPath(Path.GetFullPath("LibraryLoaded.dll"));

            AddContext(tlc);

            var prg = asm.DefinedTypes.Where(x => x.Name == "Program").First();

            var test = prg.DeclaredMethods.Where(x => x.Name == "Test").First();

            test.Invoke(null, null);
        }
Exemple #3
0
        public static void AddContext(TestLoadContext tlc)
        {
            Console.WriteLine($"[!] Now tracking context {tlc.Name} with following assemblies loaded: {string.Join(", ", tlc.Assemblies.Select(x => x.FullName))}");

            refs.Add(new WeakReference(tlc, true));
        }