예제 #1
0
        private static WeakReference <AssemblyLoadContext> CreateCollectible(CollectibleChecker checker)
        {
            var expectedContext = new ResourceAssemblyLoadContext(true);

            checker.SetAssemblyLoadContext(0, expectedContext);
            return(new WeakReference <AssemblyLoadContext>(expectedContext));
        }
예제 #2
0
        static void CreateAndLoadContext(CollectibleChecker checker)
        {
            var alc = new ResourceAssemblyLoadContext(true);

            checker.SetAssemblyLoadContext(0, alc);

            alc.Unload();

            // Check that any attempt to load an assembly after an explicit Unload will fail
            Assert.Throws <InvalidOperationException>(() => alc.LoadFromAssemblyPath(Path.GetFullPath("none.dll")));
        }
예제 #3
0
            public void CreateContextAndLoadAssembly(int contextIndex = 0)
            {
                var asmName = new AssemblyName(TestAssembly);

                _contexts[contextIndex] = new ResourceAssemblyLoadContext(true)
                {
                    LoadBy = LoadBy.Path
                };

                Assembly asm = _contexts[contextIndex].LoadFromAssemblyName(asmName);

                Assert.NotNull(asm);
                _testClassTypes[contextIndex] = asm.DefinedTypes.FirstOrDefault(t => t.Name == "TestClass");
                Assert.NotNull(_testClassTypes[contextIndex]);

                _checker.SetAssemblyLoadContext(contextIndex, _contexts[contextIndex]);
            }