[linker] Method decorated with System.Runtime.Serialization.*Attribute must be marked...
authorSebastien Pouliot <sebastien@xamarin.com>
Sat, 23 Apr 2016 09:05:38 +0000 (05:05 -0400)
committerSebastien Pouliot <sebastien@xamarin.com>
Sat, 23 Apr 2016 09:05:38 +0000 (05:05 -0400)
Some serialization attributes are unlikely to have direct reference,
from IL, but will be needed at runtime to correctly serialize (or
deserialize) objects.

* OnDeserializedAttribute
* OnDeserializingAttribute
* OnSerializedAttribute
* OnSerializingAttribute

This, along with aad627c5e8ddf15397c87fa2d3e18b54f929c927, fixed bug
40574. The later part will have new unit tests in XI.

references:
https://bugzilla.xamarin.com/show_bug.cgi?id=40574

mcs/tools/linker/Mono.Linker.Steps/MarkStep.cs

index 0e99e810203cb39600c34ab5c6d2fc6c67ae4b35..74e61e3541c895af113ea346790d598269aa3ff8 100644 (file)
@@ -527,6 +527,7 @@ namespace Mono.Linker.Steps {
                        if (type.HasMethods) {
                                MarkMethodsIf (type.Methods, IsVirtualAndHasPreservedParent);
                                MarkMethodsIf (type.Methods, IsStaticConstructorPredicate);
+                               MarkMethodsIf (type.Methods, HasSerializationAttribute);
                        }
 
                        DoAdditionalTypeProcessing (type);
@@ -740,6 +741,25 @@ namespace Mono.Linker.Steps {
                        return method.IsConstructor && method.IsStatic;
                }
 
+               static bool HasSerializationAttribute (MethodDefinition method)
+               {
+                       if (!method.HasCustomAttributes)
+                               return false;
+                       foreach (var ca in method.CustomAttributes) {
+                               var cat = ca.AttributeType;
+                               if (cat.Namespace != "System.Runtime.Serialization")
+                                       continue;
+                               switch (cat.Name) {
+                               case "OnDeserializedAttribute":
+                               case "OnDeserializingAttribute":
+                               case "OnSerializedAttribute":
+                               case "OnSerializingAttribute":
+                                       return true;
+                               }
+                       }
+                       return false;
+               }
+
                static bool IsSerializable (TypeDefinition td)
                {
                        return (td.Attributes & TypeAttributes.Serializable) != 0;