Exemple #1
0
        private static void Marshalling()
        {
            Program.GetDomainInfo(AppDomain.CurrentDomain);
            Console.WriteLine();

            AppDomain domain = AppDomain.CreateDomain("Marshalling");

            Assembly asm = Assembly.GetExecutingAssembly();

            Console.WriteLine("MarshalByRef");
            MarshalByRef clByRef = (MarshalByRef)domain.CreateInstanceAndUnwrap(asm.FullName, "Domains.MarshalByRef");

            Console.WriteLine("Is Proxy - {0}", RemotingServices.IsTransparentProxy(clByRef));
            Console.WriteLine();

            Console.WriteLine("MarshalByVal");
            MarshalByVal clByVal = (MarshalByVal)domain.CreateInstanceAndUnwrap(asm.FullName, "Domains.MarshalByVal");// clByRef.GetClassByVal();

            Console.WriteLine("Is Proxy - {0}", RemotingServices.IsTransparentProxy(clByVal));
            clByVal.Print();
            Console.WriteLine();

            Console.WriteLine("NoMarshal:");
            try
            {
                NoMarshal noMarshal = clByRef.NoMarshal();
                Console.WriteLine("Is Proxy - {0}", RemotingServices.IsTransparentProxy(noMarshal));
                Console.WriteLine();
            }
            catch (System.Runtime.Serialization.SerializationException e)
            {
                Console.WriteLine("Exception: {0}", e.Message);
            }
        }
Exemple #2
0
        private static void CreateClassInNewDomain()
        {
            Program.GetDomainInfo(AppDomain.CurrentDomain);

            try
            {
                AppDomain    newDomain = AppDomain.CreateDomain("NewDomain");
                ObjectHandle obj       = newDomain.CreateInstance(Assembly.GetExecutingAssembly().FullName, typeof(MarshalByRef).FullName);
                MarshalByRef cl        = (MarshalByRef)obj.Unwrap();
                Console.WriteLine("Is Proxy - {0}", RemotingServices.IsTransparentProxy(cl));
                //cl.GetDomainInfo();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception - " + e.Message);
            }
        }