From: Miguel de Icaza Date: Sat, 14 Jan 2012 20:35:29 +0000 (-0500) Subject: Apply patch from Tom Hindle to fix ##2893 and add a test case. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=07b6638343e9b37ba2c7c4656c8641c2eb148727;p=mono.git Apply patch from Tom Hindle to fix ##2893 and add a test case. The serializer interpreted was broken, but the compiled version was fine, running MONO_XMLSERIALIZER_THS=0 allowed this to run --- diff --git a/mcs/class/System.XML/Makefile b/mcs/class/System.XML/Makefile index e30541c3d82..18e28407765 100644 --- a/mcs/class/System.XML/Makefile +++ b/mcs/class/System.XML/Makefile @@ -26,7 +26,7 @@ endif ifeq (2.1, $(FRAMEWORK_VERSION)) LIB_MCS_FLAGS += -unsafe -d:AGCLR -d:NET_2_1_HACK endif -TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -nowarn:0618 -nowarn:219 -nowarn:169 +TEST_MCS_FLAGS = $(LIB_MCS_FLAGS) -nowarn:0618 -nowarn:219 -nowarn:169 -r:System.Data ifeq (2.0, $(FRAMEWORK_VERSION)) # Happens on net_2_0_bootstrap and net_2_0 profiles diff --git a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs index dad96241215..6faf77f97d5 100644 --- a/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs +++ b/mcs/class/System.XML/System.Xml.Serialization/XmlSerializationWriterInterpreter.cs @@ -483,7 +483,10 @@ namespace System.Xml.Serialization #if MOONLIGHT throw new NotSupportedException (); #else - if (member.TypeData.Type == typeof (XmlElement)) { + // + // XmlAnyElement can be of XmlElement or XmlNode type + // + if (member.TypeData.Type == typeof (XmlElement) || member.TypeData.Type == typeof(XmlNode)) { memberValue = new object[] { memberValue }; } diff --git a/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs b/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs index 8061423ee01..a7f00ab1e24 100644 --- a/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs +++ b/mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs @@ -31,6 +31,7 @@ using System.Globalization; using System.IO; using System.Text; using System.Xml; +using System.Data; using System.Xml.Schema; using System.Xml.Serialization; #if NET_2_0 @@ -2845,6 +2846,39 @@ namespace MonoTests.System.XmlSerialization new XmlSerializer (typeof (XmlAnyElementForObjectsType)).Serialize (TextWriter.Null, new XmlAnyElementForObjectsType ()); } + + public class Bug2893 { + public Bug2893 () + { + Contents = new XmlDataDocument(); + } + + [XmlAnyElement("Contents")] + public XmlNode Contents; + } + + // Bug Xamarin #2893 + [Test] + public void XmlAnyElementForXmlNode () + { + var obj = new Bug2893 (); + XmlSerializer mySerializer = new XmlSerializer(typeof(Bug2893)); + XmlWriterSettings settings = new XmlWriterSettings(); + + var xsn = new XmlSerializerNamespaces(); + xsn.Add(string.Empty, string.Empty); + + byte[] buffer = new byte[2048]; + var ms = new MemoryStream(buffer); + using (var xw = XmlWriter.Create(ms, settings)) + { + mySerializer.Serialize(xw, obj, xsn); + xw.Flush(); + } + + mySerializer.Serialize(ms, obj); + } + [Test] public void XmlRootOverridesSchemaProviderQName () {