public static void LoadFromAssemblyName_ValidTrustedPlatformAssembly()
        {
            var asmName     = AssemblyLoadContext.GetAssemblyName("System.Runtime.dll");
            var loadContext = new CustomTPALoadContext();

            // Usage of TPA and AssemblyLoadContext is mutually exclusive, you cannot use both.
            // Since the premise is that you either want to use the default binding mechanism (via coreclr TPA binder)
            // or supply your own (via AssemblyLoadContext) for your own assemblies.
            Assert.Throws(typeof(FileLoadException),
                          () => loadContext.LoadFromAssemblyName(asmName));
        }
        public static void LoadFromAssemblyName_ValidTrustedPlatformAssembly()
        {
            var asmName = AssemblyLoadContext.GetAssemblyName("System.Runtime.dll");
            var loadContext = new CustomTPALoadContext();

            // Usage of TPA and AssemblyLoadContext is mutually exclusive, you cannot use both.
            // Since the premise is that you either want to use the default binding mechanism (via coreclr TPA binder) 
            // or supply your own (via AssemblyLoadContext) for your own assemblies.
            Assert.Throws(typeof(FileLoadException), 
                () => loadContext.LoadFromAssemblyName(asmName));
        }
        public static void LoadFromAssemblyName_ValidTrustedPlatformAssembly()
        {
            var asmName     = AssemblyLoadContext.GetAssemblyName("System.Runtime.dll");
            var loadContext = new CustomTPALoadContext();

            // We should be able to override (and thus, load) assemblies that were
            // loaded in TPA load context.
            var asm = loadContext.LoadFromAssemblyName(asmName);

            Assert.NotNull(asm);
            var loadedContext = AssemblyLoadContext.GetLoadContext(asm);

            Assert.NotNull(loadedContext);
            Assert.Same(loadContext, loadedContext);
        }
Exemple #4
0
        public static void LoadFromAssemblyName_ValidTrustedPlatformAssembly()
        {
            var asmName = typeof(ISet <>).Assembly.GetName();

            asmName.CodeBase = null;
            var loadContext = new CustomTPALoadContext();

            // We should be able to override (and thus, load) assemblies that were
            // loaded in TPA load context.
            var asm = loadContext.LoadFromAssemblyName(asmName);

            Assert.NotNull(asm);
            var loadedContext = AssemblyLoadContext.GetLoadContext(asm);

            Assert.NotNull(loadedContext);
            Assert.Same(loadContext, loadedContext);
        }
Exemple #5
0
        public static void LoadFromAssemblyName_ValidTrustedPlatformAssembly()
        {
            string originalDir = Environment.CurrentDirectory;

            try
            {
                Environment.CurrentDirectory = AppContext.BaseDirectory;
                var asmName     = AssemblyLoadContext.GetAssemblyName("System.Runtime.dll");
                var loadContext = new CustomTPALoadContext();

                // We should be able to override (and thus, load) assemblies that were
                // loaded in TPA load context.
                var asm = loadContext.LoadFromAssemblyName(asmName);
                Assert.NotNull(asm);
                var loadedContext = AssemblyLoadContext.GetLoadContext(asm);
                Assert.NotNull(loadedContext);
                Assert.Same(loadContext, loadedContext);
            }
            finally
            {
                Environment.CurrentDirectory = originalDir;
            }
        }
        public static void LoadFromAssemblyName_ValidTrustedPlatformAssembly()
        {
            var asmName = AssemblyLoadContext.GetAssemblyName("System.Runtime.dll");
            var loadContext = new CustomTPALoadContext();

            // We should be able to override (and thus, load) assemblies that were
            // loaded in TPA load context.
            var asm = loadContext.LoadFromAssemblyName(asmName);
            Assert.NotNull(asm);
            var loadedContext = AssemblyLoadContext.GetLoadContext(asm);
            Assert.NotNull(loadedContext);
            Assert.Same(loadContext, loadedContext);
        }