Пример #1
0
        void TestAssemblyLoad(bool isolated, Func <string, Assembly> assemblyLoad)
        {
            TestResolveMissingAssembly(isolated, (string assemblyName) => assemblyLoad(assemblyName));

            using (ContextualReflectionProxy.EnterContextualReflection((Assembly)null))
            {
                Assembly assembly = assemblyLoad("ContextualReflection");

                Assert.AreEqual(isolated ? alc : AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(assembly));

                Assembly depends = assemblyLoad("ContextualReflectionDependency");

                Assert.AreEqual(AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(depends));
            }
            using (ContextualReflectionProxy.EnterContextualReflection(AssemblyLoadContext.Default))
            {
                Assembly assembly = assemblyLoad("ContextualReflection");

                Assert.AreEqual(AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(assembly));

                Assembly depends = assemblyLoad("ContextualReflectionDependency");

                Assert.AreEqual(AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(depends));
            }
            using (ContextualReflectionProxy.EnterContextualReflection(alc))
            {
                Assembly assembly = assemblyLoad("ContextualReflection");

                Assert.AreEqual(alc, AssemblyLoadContext.GetLoadContext(assembly));

                Assembly depends = assemblyLoad("ContextualReflectionDependency");

                Assert.AreEqual(AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(depends));
            }
        }
Пример #2
0
        void VerifyContextualReflectionProxy()
        {
            Assert.IsNull(ContextualReflectionProxy.CurrentContextualReflectionContext);

            using (ContextualReflectionProxy.EnterContextualReflection(alc))
            {
                Assert.AreEqual(alc, ContextualReflectionProxy.CurrentContextualReflectionContext);
                using (ContextualReflectionProxy.EnterContextualReflection(AssemblyLoadContext.Default))
                {
                    Assert.AreEqual(AssemblyLoadContext.Default, ContextualReflectionProxy.CurrentContextualReflectionContext);
                    using (ContextualReflectionProxy.EnterContextualReflection((Assembly)null))
                    {
                        Assert.IsNull(ContextualReflectionProxy.CurrentContextualReflectionContext);
                        using (ContextualReflectionProxy.EnterContextualReflection(alcAssembly))
                        {
                            Assert.AreEqual(alc, ContextualReflectionProxy.CurrentContextualReflectionContext);
                        }
                        Assert.IsNull(ContextualReflectionProxy.CurrentContextualReflectionContext);
                    }
                    Assert.AreEqual(AssemblyLoadContext.Default, ContextualReflectionProxy.CurrentContextualReflectionContext);
                }
                Assert.AreEqual(alc, ContextualReflectionProxy.CurrentContextualReflectionContext);
            }
            Assert.IsNull(ContextualReflectionProxy.CurrentContextualReflectionContext);
        }
Пример #3
0
 void TestResolveMissingAssembly(bool isolated, Action <string> action, bool skipNullIsolated = false)
 {
     using (ContextualReflectionProxy.EnterContextualReflection((Assembly)null))
     {
         TestResolve.Assert(ResolveEvents.ExpectedEvent, () => action("TestDefaultLoad"));
         if (!skipNullIsolated)
         {
             TestResolve.Assert(isolated ? ResolveEvents.ExpectedEvent : ResolveEvents.NoEvent, () => action("TestIsolatedLoad"));
         }
     }
     using (ContextualReflectionProxy.EnterContextualReflection(AssemblyLoadContext.Default))
     {
         TestResolve.Assert(ResolveEvents.ExpectedEvent, () => action("TestDefaultLoad"));
         TestResolve.Assert(ResolveEvents.NoEvent, () => action("TestIsolatedLoad"));
     }
     using (ContextualReflectionProxy.EnterContextualReflection(alc))
     {
         TestResolve.Assert(ResolveEvents.ExpectedEvent, () => action("TestDefaultLoad"));
         TestResolve.Assert(ResolveEvents.ExpectedEvent, () => action("TestIsolatedLoad"));
     }
 }
Пример #4
0
 void TestMockAssemblyThrows()
 {
     Exception e = Assert.ThrowsArgumentException("activating", () => ContextualReflectionProxy.EnterContextualReflection(new MockAssembly()));
 }
Пример #5
0
        void TestActivatorCreateInstance(bool isolated)
        {
            TestResolveMissingAssembly(isolated, (string assemblyName) => Activator.CreateInstance(assemblyName, "MyType"));
            TestResolveMissingAssembly(isolated,
                                       (string assemblyName) => Activator.CreateInstance("System.Private.CoreLib", string.Format("System.Collections.Generic.List`1[[MyType, {0}]]", assemblyName)),
                                       skipNullIsolated: true);

            TestResolveMissingAssembly(isolated,
                                       (string assemblyName) => Activator.CreateInstance("ContextualReflection", string.Format("ContextualReflectionTest.AGenericClass`1[[MyType, {0}]]", assemblyName)));

            Assembly assembly = Assembly.GetExecutingAssembly();

            using (ContextualReflectionProxy.EnterContextualReflection((Assembly)null))
            {
                {
                    ObjectHandle objectHandle = Activator.CreateInstance(null, "ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program]]");
                    Type         g            = objectHandle.Unwrap().GetType();

                    Assert.IsNotNull(g);
                    Assert.AreEqual(assembly, g.Assembly);
                    Assert.AreEqual(assembly, g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(Assembly.GetExecutingAssembly(), g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(typeof(Program), g.GenericTypeArguments[0]);
                }
                {
                    ObjectHandle objectHandle = Activator.CreateInstance(null, "ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program, ContextualReflection]]");
                    Type         g            = objectHandle.Unwrap().GetType();

                    Assert.IsNotNull(g);
                    Assert.AreEqual(assembly, g.Assembly);
                    Assert.AreEqual(assembly, g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(Assembly.GetExecutingAssembly(), g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(typeof(Program), g.GenericTypeArguments[0]);
                }
                {
                    ObjectHandle objectHandle = Activator.CreateInstance("ContextualReflection", "ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program, ContextualReflection]]");
                    Type         g            = objectHandle.Unwrap().GetType();

                    Assembly expectedAssembly = assembly;

                    Assert.IsNotNull(g);
                    Assert.AreEqual(expectedAssembly, g.Assembly);
                    Assert.AreEqual(expectedAssembly, g.GenericTypeArguments[0].Assembly);
                }
                {
                    Assembly expectedAssembly = alcAssembly;

                    Assembly mscorlib = typeof(System.Collections.Generic.List <string>).Assembly;

                    ObjectHandle objectHandle = Activator.CreateInstance(mscorlib.GetName().Name, "System.Collections.Generic.List`1[[ContextualReflectionTest.Program, ContextualReflection]]");
                    Type         m            = objectHandle.Unwrap().GetType();

                    Assert.IsNotNull(m);
                    Assert.AreEqual(mscorlib, m.Assembly);
                    Assert.AreEqual(AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(m.GenericTypeArguments[0].Assembly));
                }
            }
            using (ContextualReflectionProxy.EnterContextualReflection(AssemblyLoadContext.Default))
            {
                {
                    ObjectHandle objectHandle = Activator.CreateInstance(null, "ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program]]");
                    Type         g            = objectHandle.Unwrap().GetType();

                    Assert.IsNotNull(g);
                    Assert.AreEqual(assembly, g.Assembly);
                    Assert.AreEqual(assembly, g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(Assembly.GetExecutingAssembly(), g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(typeof(Program), g.GenericTypeArguments[0]);
                }
                {
                    ObjectHandle objectHandle = Activator.CreateInstance(null, "ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program, ContextualReflection]]");
                    Type         g            = objectHandle.Unwrap().GetType();

                    Assembly expectedAssembly = defaultAssembly;

                    Assert.IsNotNull(g);
                    Assert.AreEqual(assembly, g.Assembly);
                    Assert.AreEqual(expectedAssembly, g.GenericTypeArguments[0].Assembly);
                }
                {
                    ObjectHandle objectHandle = Activator.CreateInstance("ContextualReflection", "ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program, ContextualReflection]]");
                    Type         g            = objectHandle.Unwrap().GetType();

                    Assembly expectedAssembly = defaultAssembly;

                    Assert.IsNotNull(g);
                    Assert.AreEqual(expectedAssembly, g.Assembly);
                    Assert.AreEqual(expectedAssembly, g.GenericTypeArguments[0].Assembly);
                }
                {
                    Assembly mscorlib = typeof(System.Collections.Generic.List <string>).Assembly;

                    ObjectHandle objectHandle = Activator.CreateInstance(mscorlib.GetName().Name, "System.Collections.Generic.List`1[[ContextualReflectionTest.Program, ContextualReflection]]");
                    Type         m            = objectHandle.Unwrap().GetType();

                    Assembly expectedAssembly = mscorlib;

                    Assert.IsNotNull(m);
                    Assert.AreEqual(expectedAssembly, m.Assembly);
                    Assert.AreEqual(AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(m.GenericTypeArguments[0].Assembly));
                }
            }
            using (ContextualReflectionProxy.EnterContextualReflection(alc))
            {
                {
                    ObjectHandle objectHandle = Activator.CreateInstance(null, "ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program]]");
                    Type         g            = objectHandle.Unwrap().GetType();

                    Assert.IsNotNull(g);
                    Assert.AreEqual(assembly, g.Assembly);
                    Assert.AreEqual(assembly, g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(Assembly.GetExecutingAssembly(), g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(typeof(Program), g.GenericTypeArguments[0]);
                }
                {
                    ObjectHandle objectHandle = Activator.CreateInstance(null, "ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program, ContextualReflection]]");
                    Type         g            = objectHandle.Unwrap().GetType();

                    Assembly expectedAssembly = alcAssembly;

                    Assert.IsNotNull(g);
                    Assert.AreEqual(assembly, g.Assembly);
                    Assert.AreEqual(expectedAssembly, g.GenericTypeArguments[0].Assembly);
                }
                {
                    ObjectHandle objectHandle = Activator.CreateInstance("ContextualReflection", "ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program, ContextualReflection]]");
                    Type         g            = objectHandle.Unwrap().GetType();

                    Assembly expectedAssembly = alcAssembly;

                    Assert.IsNotNull(g);
                    Assert.AreEqual(expectedAssembly, g.Assembly);
                    Assert.AreEqual(expectedAssembly, g.GenericTypeArguments[0].Assembly);
                }
                {
                    Assembly mscorlib = typeof(System.Collections.Generic.List <string>).Assembly;

                    ObjectHandle objectHandle = Activator.CreateInstance(mscorlib.GetName().Name, "System.Collections.Generic.List`1[[ContextualReflectionTest.Program, ContextualReflection]]");
                    Type         m            = objectHandle.Unwrap().GetType();

                    Assert.IsNotNull(m);
                    Assert.AreEqual(mscorlib, m.Assembly);
                    Assert.AreEqual(alc, AssemblyLoadContext.GetLoadContext(m.GenericTypeArguments[0].Assembly));
                }
            }
        }
Пример #6
0
        void TestAssemblyGetType(bool isolated)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            TestResolveMissingAssembly(isolated,
                                       (string assemblyName) => assembly.GetType(string.Format("ContextualReflectionTest.AGenericClass`1[[MyType, {0}]]", assemblyName)));

            using (ContextualReflectionProxy.EnterContextualReflection((Assembly)null))
            {
                {
                    Type g = assembly.GetType("ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program]]", throwOnError: false);

                    Assert.IsNotNull(g);
                    Assert.AreEqual(assembly, g.Assembly);
                    Assert.AreEqual(assembly, g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(Assembly.GetExecutingAssembly(), g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(typeof(Program), g.GenericTypeArguments[0]);
                }
                {
                    Type g = assembly.GetType("ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program, ContextualReflection]]", throwOnError: false);

                    Assert.IsNotNull(g);
                    Assert.AreEqual(assembly, g.Assembly);
                    Assert.AreEqual(assembly, g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(Assembly.GetExecutingAssembly(), g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(typeof(Program), g.GenericTypeArguments[0]);
                }
                {
                    Assembly mscorlib = typeof(System.Collections.Generic.List <string>).Assembly;

                    Type m = mscorlib.GetType("System.Collections.Generic.List`1[[ContextualReflectionTest.Program, ContextualReflection]]", throwOnError: false);

                    Assembly expectedAssembly = mscorlib;

                    Assert.IsNotNull(m);
                    Assert.AreEqual(expectedAssembly, m.Assembly);
                    Assert.AreEqual(AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(m.GenericTypeArguments[0].Assembly));
                }
            }
            using (ContextualReflectionProxy.EnterContextualReflection(AssemblyLoadContext.Default))
            {
                {
                    Type g = assembly.GetType("ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program]]", throwOnError: false);

                    Assert.IsNotNull(g);
                    Assert.AreEqual(assembly, g.Assembly);
                    Assert.AreEqual(assembly, g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(Assembly.GetExecutingAssembly(), g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(typeof(Program), g.GenericTypeArguments[0]);
                }
                {
                    Type g = assembly.GetType("ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program, ContextualReflection]]", throwOnError: false);

                    Assembly expectedAssembly = defaultAssembly;

                    Assert.IsNotNull(g);
                    Assert.AreEqual(assembly, g.Assembly);
                    Assert.AreEqual(expectedAssembly, g.GenericTypeArguments[0].Assembly);
                }
                {
                    Assembly mscorlib = typeof(System.Collections.Generic.List <string>).Assembly;

                    Type m = mscorlib.GetType("System.Collections.Generic.List`1[[ContextualReflectionTest.Program, ContextualReflection]]", throwOnError: false);

                    Assembly expectedAssembly = mscorlib;

                    Assert.IsNotNull(m);
                    Assert.AreEqual(expectedAssembly, m.Assembly);
                    Assert.AreEqual(AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(m.GenericTypeArguments[0].Assembly));
                }
            }
            using (ContextualReflectionProxy.EnterContextualReflection(alc))
            {
                {
                    Type g = assembly.GetType("ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program]]", throwOnError: false);

                    Assert.IsNotNull(g);
                    Assert.AreEqual(assembly, g.Assembly);
                    Assert.AreEqual(assembly, g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(Assembly.GetExecutingAssembly(), g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(typeof(Program), g.GenericTypeArguments[0]);
                }
                {
                    Type g = assembly.GetType("ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program, ContextualReflection]]", throwOnError: false);

                    Assembly expectedAssembly = alcAssembly;

                    Assert.IsNotNull(g);
                    Assert.AreEqual(assembly, g.Assembly);
                    Assert.AreEqual(expectedAssembly, g.GenericTypeArguments[0].Assembly);
                }
                {
                    Assembly mscorlib = typeof(System.Collections.Generic.List <string>).Assembly;

                    Type m = mscorlib.GetType("System.Collections.Generic.List`1[[ContextualReflectionTest.Program, ContextualReflection]]", throwOnError: false);

                    Assembly expectedAssembly = mscorlib;

                    Assert.IsNotNull(m);
                    Assert.AreEqual(expectedAssembly, m.Assembly);
                    Assert.AreEqual(alc, AssemblyLoadContext.GetLoadContext(m.GenericTypeArguments[0].Assembly));
                }
            }
        }
Пример #7
0
        void TestTypeGetType(bool isolated, Func <string, System.Type> typeGetType)
        {
            TestResolveMissingAssembly(isolated, (string assemblyName) => typeGetType(string.Format("MyType, {0}", assemblyName)));

            using (ContextualReflectionProxy.EnterContextualReflection((Assembly)null))
            {
                {
                    Type p = typeGetType("ContextualReflectionTest.Program");

                    Assembly expectedAssembly = Assembly.GetExecutingAssembly();

                    Assert.IsNotNull(p);
                    Assert.AreEqual(expectedAssembly, p.Assembly);
                    Assert.AreEqual(typeof(Program), p);
                }
                {
                    Type p = typeGetType("ContextualReflectionTest.Program, ContextualReflection");

                    Assembly expectedAssembly = Assembly.GetExecutingAssembly();

                    Assert.IsNotNull(p);
                    Assert.AreEqual(expectedAssembly, p.Assembly);
                    Assert.AreEqual(typeof(Program), p);
                }
                {
                    Type g = typeGetType("ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program, ContextualReflection]], ContextualReflection");

                    Assembly expectedAssembly = Assembly.GetExecutingAssembly();

                    Assert.IsNotNull(g);
                    Assert.AreEqual(expectedAssembly, g.Assembly);
                    Assert.AreEqual(expectedAssembly, g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(typeof(Program), g.GenericTypeArguments[0]);
                    Assert.AreEqual(isolated ? alc : AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(g.GenericTypeArguments[0].Assembly));
                }
            }
            using (ContextualReflectionProxy.EnterContextualReflection(AssemblyLoadContext.Default))
            {
                {
                    Type p = typeGetType("ContextualReflectionTest.Program");

                    Assembly expectedAssembly = Assembly.GetExecutingAssembly();

                    Assert.IsNotNull(p);
                    Assert.AreEqual(expectedAssembly, p.Assembly);
                    Assert.AreEqual(typeof(Program), p);
                }
                {
                    Type p = typeGetType("ContextualReflectionTest.Program, ContextualReflection");

                    Assembly expectedAssembly = defaultAssembly;

                    Assert.IsNotNull(p);
                    Assert.AreEqual(expectedAssembly, p.Assembly);
                    Assert.AreEqual(AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(p.Assembly));
                }
                {
                    Type g = typeGetType("ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program, ContextualReflection]], ContextualReflection");

                    Assembly expectedAssembly = defaultAssembly;

                    Assert.IsNotNull(g);
                    Assert.AreEqual(expectedAssembly, g.Assembly);
                    Assert.AreEqual(expectedAssembly, g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(g.Assembly));
                    Assert.AreEqual(AssemblyLoadContext.Default, AssemblyLoadContext.GetLoadContext(g.GenericTypeArguments[0].Assembly));
                }
            }
            using (ContextualReflectionProxy.EnterContextualReflection(alc))
            {
                {
                    Type p = typeGetType("ContextualReflectionTest.Program");

                    Assembly expectedAssembly = Assembly.GetExecutingAssembly();

                    Assert.IsNotNull(p);
                    Assert.AreEqual(expectedAssembly, p.Assembly);
                    Assert.AreEqual(typeof(Program), p);
                }
                {
                    Type p = typeGetType("ContextualReflectionTest.Program, ContextualReflection");

                    Assembly expectedAssembly = alcAssembly;

                    Assert.IsNotNull(p);
                    Assert.AreEqual(expectedAssembly, p.Assembly);
                    Assert.AreEqual(alc, AssemblyLoadContext.GetLoadContext(p.Assembly));
                }
                {
                    Type g = typeGetType("ContextualReflectionTest.AGenericClass`1[[ContextualReflectionTest.Program, ContextualReflection]], ContextualReflection");

                    Assembly expectedAssembly = alcAssembly;

                    Assert.IsNotNull(g);
                    Assert.AreEqual(expectedAssembly, g.Assembly);
                    Assert.AreEqual(expectedAssembly, g.GenericTypeArguments[0].Assembly);
                    Assert.AreEqual(alc, AssemblyLoadContext.GetLoadContext(g.Assembly));
                    Assert.AreEqual(alc, AssemblyLoadContext.GetLoadContext(g.GenericTypeArguments[0].Assembly));
                }
            }
        }
Пример #8
0
        void VerifyBadContextualReflectionUsage()
        {
            Assert.IsNull(ContextualReflectionProxy.CurrentContextualReflectionContext);

            {
                IDisposable alcScope = ContextualReflectionProxy.EnterContextualReflection(alc);
                Assert.AreEqual(alc, ContextualReflectionProxy.CurrentContextualReflectionContext);
                alcScope.Dispose();
            }

            Assert.IsNull(ContextualReflectionProxy.CurrentContextualReflectionContext);

            {
                IDisposable alcScope = ContextualReflectionProxy.EnterContextualReflection(alc);
                Assert.AreEqual(alc, ContextualReflectionProxy.CurrentContextualReflectionContext);
                alcScope.Dispose();
                alcScope.Dispose();
            }

            Assert.IsNull(ContextualReflectionProxy.CurrentContextualReflectionContext);

            {
                IDisposable alcScope = ContextualReflectionProxy.EnterContextualReflection(alc);
                Assert.AreEqual(alc, ContextualReflectionProxy.CurrentContextualReflectionContext);
                IDisposable defaultScope = ContextualReflectionProxy.EnterContextualReflection(AssemblyLoadContext.Default);
                Assert.AreEqual(AssemblyLoadContext.Default, ContextualReflectionProxy.CurrentContextualReflectionContext);
                defaultScope.Dispose();
                Assert.AreEqual(alc, ContextualReflectionProxy.CurrentContextualReflectionContext);
                alcScope.Dispose();
            }

            Assert.IsNull(ContextualReflectionProxy.CurrentContextualReflectionContext);

            {
                IDisposable alcScope = ContextualReflectionProxy.EnterContextualReflection(alc);
                Assert.AreEqual(alc, ContextualReflectionProxy.CurrentContextualReflectionContext);
                IDisposable defaultScope = ContextualReflectionProxy.EnterContextualReflection(AssemblyLoadContext.Default);
                Assert.AreEqual(AssemblyLoadContext.Default, ContextualReflectionProxy.CurrentContextualReflectionContext);

                alcScope.Dispose();
                Assert.IsNull(ContextualReflectionProxy.CurrentContextualReflectionContext);

                defaultScope.Dispose();
                Assert.AreEqual(alc, ContextualReflectionProxy.CurrentContextualReflectionContext);
                alcScope.Dispose();
            }

            Assert.IsNull(ContextualReflectionProxy.CurrentContextualReflectionContext);

            {
                IDisposable alcScope = ContextualReflectionProxy.EnterContextualReflection(alc);
                Assert.AreEqual(alc, ContextualReflectionProxy.CurrentContextualReflectionContext);
                try
                {
                    IDisposable defaultScope = ContextualReflectionProxy.EnterContextualReflection((Assembly)null);
                    Assert.AreEqual(null, ContextualReflectionProxy.CurrentContextualReflectionContext);

                    throw new InvalidOperationException();
                }
                catch
                {
                }
            }

            Assert.IsNull(ContextualReflectionProxy.CurrentContextualReflectionContext);
        }