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

            checker.SetAssemblyLoadContext(0, expectedContext);
            return(new WeakReference <AssemblyLoadContext>(expectedContext));
        }
        public static void InitializeDefaultContextTest()
        {
            var loadContext = new ResourceAssemblyLoadContext();

            // because the coreclr binding model is already locked for the appdomain
            // and cannot be reset
            Assert.Throws(typeof(InvalidOperationException),
                          () => AssemblyLoadContext.InitializeDefaultContext(loadContext));
        }
        public static void LoadFromAssemblyName_AssemblyNotFound()
        {
            var asmName = new AssemblyName("Non.Existing.Assembly.dll");
            var loadContext = new ResourceAssemblyLoadContext();
            loadContext.LoadBy = LoadBy.Path;

            Assert.Throws(typeof(FileNotFoundException), 
                () => loadContext.LoadFromAssemblyName(asmName));
        }
        public static void LoadFromAssemblyName_AssemblyNotFound()
        {
            var asmName     = new AssemblyName("Non.Existing.Assembly.dll");
            var loadContext = new ResourceAssemblyLoadContext();

            loadContext.LoadBy = LoadBy.Path;

            Assert.Throws <FileNotFoundException>(() => loadContext.LoadFromAssemblyName(asmName));
        }
Exemple #5
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")));
        }
        public static void LoadAssemblyByStream_ValidUserAssembly()
        {
            var asmName = new AssemblyName(TestAssembly);
            var loadContext = new ResourceAssemblyLoadContext();
            loadContext.LoadBy = LoadBy.Stream;

            var asm = loadContext.LoadFromAssemblyName(asmName);

            Assert.NotNull(asm);
            Assert.True(asm.DefinedTypes.Any(t => t.Name == "TestClass"));
        }
Exemple #7
0
        public static void SubclassAssemblyLoadContext_Properties()
        {
            AssemblyLoadContext alc = new ResourceAssemblyLoadContext();

            Assert.False(alc.IsCollectible);
            Assert.Null(alc.Name);
            Assert.Contains("\"\"", alc.ToString());
            Assert.Contains(typeof(ResourceAssemblyLoadContext).ToString(), alc.ToString());
            Assert.Contains(alc, AssemblyLoadContext.All);
            Assert.Empty(alc.Assemblies);
        }
        public static void GetLoadContextTest_ValidUserAssembly()
        {
            var asmName         = new AssemblyName(TestAssembly);
            var expectedContext = new ResourceAssemblyLoadContext();

            expectedContext.LoadBy = LoadBy.Stream;

            var asm           = expectedContext.LoadFromAssemblyName(asmName);
            var actualContext = AssemblyLoadContext.GetLoadContext(asm);

            Assert.Equal(expectedContext, actualContext);
        }
        public static void LoadAssemblyByStream_ValidUserAssembly()
        {
            var asmName     = new AssemblyName(TestAssembly);
            var loadContext = new ResourceAssemblyLoadContext();

            loadContext.LoadBy = LoadBy.Stream;

            var asm = loadContext.LoadFromAssemblyName(asmName);

            Assert.NotNull(asm);
            Assert.True(asm.DefinedTypes.Any(t => t.Name == "TestClass"));
        }
Exemple #10
0
        public static void LoadAssemblyByPath_ValidUserAssembly()
        {
            var asmName     = new AssemblyName(TestAssembly);
            var loadContext = new ResourceAssemblyLoadContext();

            loadContext.LoadBy = LoadBy.Path;

            var asm = loadContext.LoadFromAssemblyName(asmName);

            Assert.NotNull(asm);
            Assert.Contains(asm.DefinedTypes, t => t.Name == "TestClass");
        }
Exemple #11
0
        public static void InitializeDefaultContextTest()
        {
            // The coreclr binding model will become locked upon loading the first assembly that is not on the TPA list, or
            // upon initializing the default context for the first time. For this test, test assemblies are located alongside
            // corerun, and hence will be on the TPA list. So, we should be able to set the default context once successfully,
            // and fail on the second try.

            var loadContext = new ResourceAssemblyLoadContext();

            AssemblyLoadContext.InitializeDefaultContext(loadContext);
            Assert.Equal(loadContext, AssemblyLoadContext.Default);

            loadContext = new ResourceAssemblyLoadContext();
            Assert.Throws(typeof(InvalidOperationException),
                          () => AssemblyLoadContext.InitializeDefaultContext(loadContext));
        }
Exemple #12
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]);
            }
Exemple #13
0
        public static void Unsupported_FixedAddressValueType()
        {
            var asmName = new AssemblyName(TestAssemblyNotSupported);
            var alc     = new ResourceAssemblyLoadContext(true)
            {
                LoadBy = LoadBy.Path
            };
            Assembly asm = alc.LoadFromAssemblyName(asmName);

            Assert.NotNull(asm);

            ReflectionTypeLoadException exception = Assert.Throws <ReflectionTypeLoadException>(() => asm.DefinedTypes);

            // Expecting two exceptions:
            //  Collectible type 'System.Runtime.Loader.Tests.TestClassNotSupported_FixedAddressValueType' has unsupported FixedAddressValueTypeAttribute applied to a field
            Assert.Equal(1, exception.LoaderExceptions.Length);
            Assert.True(exception.LoaderExceptions.All(exp => exp is TypeLoadException));
        }
        public static void GetLoadContextTest_ValidUserAssembly()
        {
            var asmName = new AssemblyName(TestAssembly);
            var expectedContext = new ResourceAssemblyLoadContext();
            expectedContext.LoadBy = LoadBy.Stream;

            var asm = expectedContext.LoadFromAssemblyName(asmName);
            var actualContext = AssemblyLoadContext.GetLoadContext(asm);

            Assert.Equal(expectedContext, actualContext);
        }
        public static void InitializeDefaultContextTest()
        {
            var loadContext = new ResourceAssemblyLoadContext();

            // because the coreclr binding model is already locked for the appdomain
            // and cannot be reset
            Assert.Throws(typeof(InvalidOperationException), 
                () => AssemblyLoadContext.InitializeDefaultContext(loadContext));
        }        
        public static void InitializeDefaultContextTest()
        {
            // The coreclr binding model will become locked upon loading the first assembly that is not on the TPA list, or
            // upon initializing the default context for the first time. For this test, test assemblies are located alongside
            // corerun, and hence will be on the TPA list. So, we should be able to set the default context once successfully,
            // and fail on the second try.

            var loadContext = new ResourceAssemblyLoadContext();
            AssemblyLoadContext.InitializeDefaultContext(loadContext);
            Assert.Equal(loadContext, AssemblyLoadContext.Default);

            loadContext = new ResourceAssemblyLoadContext();
            Assert.Throws(typeof(InvalidOperationException), 
                () => AssemblyLoadContext.InitializeDefaultContext(loadContext));
        }