diff options
author | Marcos Henrich <marcos.henrich@xamarin.com> | 2016-02-29 22:10:55 +0300 |
---|---|---|
committer | Marcos Henrich <marcos.henrich@xamarin.com> | 2016-03-29 12:09:38 +0300 |
commit | 8a1e9242f6d25e408644d0339dcf5c222d95671d (patch) | |
tree | ec31644345fabc73e38713bf0cf0c35894ae10a1 /mcs/class/System.Runtime.Serialization | |
parent | e8744b6fc010b497b44143c8a9cbc7a67ca4c026 (diff) |
[System.Runtime.Serialization] Static writer fix.
While serializing any type into a contract member of type object an
exception would be thrown.
To avoid this XmlObjectSerializerWriteContext.InternalSerialize should
in this case be called using the object type instead of the member type,
similar how reference sources does in type instead of the member type,
referencesources seems to be doing omething similar [1].
Fixes #37116.
[1]
http://referencesource.microsoft.com/#System.Runtime.Serialization/System/Runtime/Serialization/XmlObjectSerializerWriteContext.cs,619
Diffstat (limited to 'mcs/class/System.Runtime.Serialization')
-rw-r--r-- | mcs/class/System.Runtime.Serialization/ReferenceSources/XmlFormatWriterGenerator_static.cs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/mcs/class/System.Runtime.Serialization/ReferenceSources/XmlFormatWriterGenerator_static.cs b/mcs/class/System.Runtime.Serialization/ReferenceSources/XmlFormatWriterGenerator_static.cs index fdbcc77c5ba..f0b6d8d669a 100644 --- a/mcs/class/System.Runtime.Serialization/ReferenceSources/XmlFormatWriterGenerator_static.cs +++ b/mcs/class/System.Runtime.Serialization/ReferenceSources/XmlFormatWriterGenerator_static.cs @@ -507,11 +507,15 @@ namespace System.Runtime.Serialization } else { var typeHandleValue = Type.GetTypeHandle (memberValue); var isDeclaredType = typeHandleValue.Equals (CodeInterpreter.ConvertValue (memberValue, memberType, Globals.TypeOfObject)); - if (isNullableOfT) + if (isNullableOfT) { ctx.InternalSerialize (writer, memberValue, isDeclaredType, writeXsiType, DataContract.GetId (memberType.TypeHandle), memberType.TypeHandle); - else - ctx.InternalSerializeReference (writer, memberValue, isDeclaredType, writeXsiType, DataContract.GetId (memberType.TypeHandle), memberType.TypeHandle); - //InternalSerialize((isNullableOfT ? XmlFormatGeneratorStatics.InternalSerializeMethod : XmlFormatGeneratorStatics.InternalSerializeReferenceMethod), () => memberValue, memberType, writeXsiType); + } else if (memberType == Globals.TypeOfObject) { + var dataContract = DataContract.GetDataContract (memberValue.GetType()); + writer.WriteAttributeQualifiedName (Globals.XsiPrefix, DictionaryGlobals.XsiTypeLocalName, DictionaryGlobals.SchemaInstanceNamespace, dataContract.Name, dataContract.Namespace); + ctx.InternalSerializeReference (writer, memberValue, false, false, -1, typeHandleValue); + } else { + ctx.InternalSerializeReference (writer, memberValue, isDeclaredType, writeXsiType, DataContract.GetId (memberType.TypeHandle), memberType.TypeHandle); + } } } } |