From d6c5db881b26fd0f8ef64a65eba00e72fda552a2 Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Fri, 14 Jun 2013 19:04:55 -0400 Subject: [PATCH] Mark MonoCMethod (runtime subclass of ConstructorInfo) as serializable. Fixes #12611 --- mcs/class/corlib/System.Reflection/MonoMethod.cs | 1 + mcs/class/corlib/Test/System/AppDomainTest.cs | 73 ++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/mcs/class/corlib/System.Reflection/MonoMethod.cs b/mcs/class/corlib/System.Reflection/MonoMethod.cs index f46c01a226d..b6a119e3208 100644 --- a/mcs/class/corlib/System.Reflection/MonoMethod.cs +++ b/mcs/class/corlib/System.Reflection/MonoMethod.cs @@ -464,6 +464,7 @@ namespace System.Reflection { #endif } + [Serializable()] [StructLayout (LayoutKind.Sequential)] internal class MonoCMethod : ConstructorInfo, ISerializable { diff --git a/mcs/class/corlib/Test/System/AppDomainTest.cs b/mcs/class/corlib/Test/System/AppDomainTest.cs index 54ba7cef2a8..1d88666538f 100644 --- a/mcs/class/corlib/Test/System/AppDomainTest.cs +++ b/mcs/class/corlib/Test/System/AppDomainTest.cs @@ -3261,6 +3261,74 @@ namespace MonoTests.System } #endif + public class StuffToPick + { + public StuffToPick () {} + public void Method () {} + public int Property { get; set; } + public event Action Event; + public int Field; + public void GenericMethod () {} + } + + public class StuffToPick + { + public StuffToPick () {} + public void Method () {} + public int Property { get; set; } + public event Action Event; + public int Field; + public void GenericMethod () {} + } + + static void TestSerialization (CrossDomainTester tester, object o) + { + Assert.AreSame (o, tester.ReturnArg0 (o), "serializing_type_" + o.GetType ()); + } + + [Test] //BXC #12611 + public void ReflectionObjectsAreSerializableTest () + { + ad = CreateTestDomain (tempDir, true); + CrossDomainTester tester = CreateCrossDomainTester (ad); + + TestSerialization (tester, typeof (StuffToPick)); + TestSerialization (tester, typeof (StuffToPick).GetConstructor(new Type [0])); + TestSerialization (tester, typeof (StuffToPick).GetMethod ("Method")); + TestSerialization (tester, typeof (StuffToPick).GetProperty ("Property")); + TestSerialization (tester, typeof (StuffToPick).GetEvent ("Event")); + TestSerialization (tester, typeof (StuffToPick).GetField ("Field")); + TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod")); + + TestSerialization (tester, typeof (StuffToPick<>)); + TestSerialization (tester, typeof (StuffToPick<>).GetConstructor(new Type [0])); + TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("Method")); + TestSerialization (tester, typeof (StuffToPick<>).GetProperty ("Property")); + TestSerialization (tester, typeof (StuffToPick<>).GetEvent ("Event")); + TestSerialization (tester, typeof (StuffToPick<>).GetField ("Field")); + TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("GenericMethod")); + + TestSerialization (tester, typeof (StuffToPick)); + TestSerialization (tester, typeof (StuffToPick).GetConstructor(new Type [0])); + TestSerialization (tester, typeof (StuffToPick).GetMethod ("Method")); + TestSerialization (tester, typeof (StuffToPick).GetProperty ("Property")); + TestSerialization (tester, typeof (StuffToPick).GetEvent ("Event")); + TestSerialization (tester, typeof (StuffToPick).GetField ("Field")); + TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod")); + } + + [Test] //BXC #12611 + [Category ("NotWorking")] // Serialization can't handle generic methods + public void GenericReflectionObjectsAreSerializableTest () + { + ad = CreateTestDomain (tempDir, true); + CrossDomainTester tester = CreateCrossDomainTester (ad); + + TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int))); + TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int))); + TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int))); + } + private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver) { AppDomainSetup setup = new AppDomainSetup (); @@ -3395,6 +3463,11 @@ namespace MonoTests.System return true; } } + + public object ReturnArg0 (object obj) + { + return obj; + } } [Serializable ()] -- 2.11.4.GIT