Esempio n. 1
0
        static int Main(string[] args)
        {
            Console.WriteLine("test " + AppDomain.CurrentDomain.FriendlyName);
            AppDomain app2 = AppDomain.CreateDomain("2");

            if (!RemotingServices.IsTransparentProxy(app2))
            {
                return(1);
            }

            ObjectHandle o     = AppDomain.CurrentDomain.CreateInstance(typeof(R1).Assembly.FullName, typeof(R1).FullName);
            R1           myobj = (R1)o.Unwrap();

            // should not be a proxy in our domain..
            if (RemotingServices.IsTransparentProxy(myobj))
            {
                Console.WriteLine("CreateInstance return TP for in our current domain");
                return(2);
            }

            o = app2.CreateInstance(typeof(R1).Assembly.FullName, typeof(R1).FullName);

            Console.WriteLine("type: " + o.GetType().ToString());

            myobj = (R1)o.Unwrap();
            if (!RemotingServices.IsTransparentProxy(myobj))
            {
                return(3);
            }

            Console.WriteLine("unwrapped type: " + myobj.GetType().ToString());

            R2   r2      = null;
            bool bSerExc = false;

            // this should crash
            try
            {
                r2 = myobj.TestMBV();
            }
            catch (SerializationException)
            {
                bSerExc = true;
            }

            if (!bSerExc)
            {
                return(4);
            }

            // Test generic virtual interface methods on proxies

            o     = app2.CreateInstance(typeof(R1).Assembly.FullName, typeof(R1).FullName);
            myobj = (R1)o.Unwrap();

            GenericIFace iface = (GenericIFace)myobj;

            if (iface.Foo <int> () != 0)
            {
                return(5);
            }
            if (iface.Foo <string> () != null)
            {
                return(6);
            }

            // Test type identity (#504886, comment #10 ff.)

            if (typeof(R1) != myobj.GetType())
            {
                return(7);
            }

            AppDomain.Unload(app2);

            Console.WriteLine("test-ok");
            return(0);
        }