Merge pull request #1196 from tritao/master
[mono.git] / mcs / class / System.XML / Test / System.Xml.Serialization / XmlSerializerTests.cs
index 44fb8c52cf1f9942bbb6f2cd6f50c6cc398524b5..e9a161c6e3fd422f3153cc489f51483e564a02be 100644 (file)
@@ -3,8 +3,10 @@
 //
 // Author:
 //   Erik LeBel <eriklebel@yahoo.ca>
+//   Hagit Yidov <hagity@mainsoft.com>
 //
 // (C) 2003 Erik LeBel
+// (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
 //
 //
 // NOTES:
@@ -29,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
@@ -61,8 +64,10 @@ namespace MonoTests.System.XmlSerialization
                        xtw.Formatting = Formatting.None;
                }
 
-               private string WriterText {
-                       get {
+               private string WriterText
+               {
+                       get
+                       {
                                string val = sw.GetStringBuilder ().ToString ();
                                int offset = val.IndexOf ('>') + 1;
                                val = val.Substring (offset);
@@ -220,7 +225,7 @@ namespace MonoTests.System.XmlSerialization
                [Test]
                public void TestSerializeIntArray ()
                {
-                       Serialize (new int [] { 1, 2, 3, 4 });
+                       Serialize (new int[] { 1, 2, 3, 4 });
                        Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
                                "<ArrayOfInt xmlns:xsd='{0}' xmlns:xsi='{1}'><int>1</int><int>2</int><int>3</int><int>4</int></ArrayOfInt>",
                                XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText);
@@ -229,7 +234,7 @@ namespace MonoTests.System.XmlSerialization
                [Test]
                public void TestSerializeEmptyArray ()
                {
-                       Serialize (new int [] { });
+                       Serialize (new int[] { });
                        Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
                                "<ArrayOfInt xmlns:xsd='{0}' xmlns:xsi='{1}' />",
                                XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText);
@@ -705,7 +710,7 @@ namespace MonoTests.System.XmlSerialization
                        f.Modifiers3 = MapModifiers.Public;
                        f.Modifiers4 = MapModifiers.Protected;
                        f.Modifiers5 = MapModifiers.Public;
-                       f.Names = new string [] { "a", "b" };
+                       f.Names = new string[] { "a", "b" };
                        Serialize (f, typeof (Field));
                        Assert.AreEqual (Infoset (string.Format (CultureInfo.InvariantCulture,
                                "<field xmlns:xsd='{0}' xmlns:xsi='{1}' flag1='one two' flag2='two'" +
@@ -813,7 +818,7 @@ namespace MonoTests.System.XmlSerialization
                                " modifiers3='Protected' modifiers4='PuBlIc' modifiers5='Protected'" +
                                " xmlns:q1='some:urn' />",
 #endif
-                               XmlSchema.Namespace, XmlSchema.InstanceNamespace),
+                               XmlSchema.Namespace, XmlSchema.InstanceNamespace),
                                sw.GetStringBuilder ().ToString (), "#C");
 
                        f.Flags1 = (FlagEnum_Encoded) 1;
@@ -856,12 +861,15 @@ namespace MonoTests.System.XmlSerialization
                }
 
                [Test]
+#if TARGET_JVM
+               [Ignore ("JVM returns fields in different order")]
+#endif
                public void TestSerializeGroup ()
                {
                        Group myGroup = new Group ();
                        myGroup.GroupName = ".NET";
 
-                       Byte [] hexByte = new Byte [] { 0x64, 0x32 };
+                       Byte[] hexByte = new Byte[] { 0x64, 0x32 };
                        myGroup.GroupNumber = hexByte;
 
                        DateTime myDate = new DateTime (2002, 5, 2);
@@ -962,10 +970,10 @@ namespace MonoTests.System.XmlSerialization
                [Test]
                public void TestSerializeByteArrays ()
                {
-                       Serialize (new byte [] { });
+                       Serialize (new byte[] { });
                        Assert.AreEqual (Infoset ("<base64Binary />"), WriterText);
 
-                       Serialize (new byte [] { 0xAB, 0xCD });
+                       Serialize (new byte[] { 0xAB, 0xCD });
                        Assert.AreEqual (Infoset ("<base64Binary>q80=</base64Binary>"), WriterText);
                }
 
@@ -978,7 +986,11 @@ namespace MonoTests.System.XmlSerialization
                        TimeZone tz = TimeZone.CurrentTimeZone;
                        TimeSpan off = tz.GetUtcOffset (d);
                        string sp = string.Format ("{0}{1:00}:{2:00}", off.Ticks >= 0 ? "+" : "", off.Hours, off.Minutes);
+#if NET_2_0
+                       Assert.AreEqual (Infoset ("<dateTime>0001-01-01T00:00:00</dateTime>"), WriterText);
+#else
                        Assert.AreEqual (Infoset ("<dateTime>0001-01-01T00:00:00.0000000" + sp + "</dateTime>"), WriterText);
+#endif
                }
 
                /*
@@ -1095,11 +1107,11 @@ namespace MonoTests.System.XmlSerialization
                        Serialize (container);
                        Assert.AreEqual (Infoset ("<ArrayContainer xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText);
 
-                       container.items = new object [] { 10, 20 };
+                       container.items = new object[] { 10, 20 };
                        Serialize (container);
                        Assert.AreEqual (Infoset ("<ArrayContainer xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' ><items><anyType xsi:type='xsd:int'>10</anyType><anyType xsi:type='xsd:int'>20</anyType></items></ArrayContainer>"), WriterText);
 
-                       container.items = new object [] { 10, "hello" };
+                       container.items = new object[] { 10, "hello" };
                        Serialize (container);
                        Assert.AreEqual (Infoset ("<ArrayContainer xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' ><items><anyType xsi:type='xsd:int'>10</anyType><anyType xsi:type='xsd:string'>hello</anyType></items></ArrayContainer>"), WriterText);
                }
@@ -1115,9 +1127,9 @@ namespace MonoTests.System.XmlSerialization
                        simple1.something = "hello";
                        SimpleClass simple2 = new SimpleClass ();
                        simple2.something = "hello";
-                       container.items = new SimpleClass [2];
-                       container.items [0] = simple1;
-                       container.items [1] = simple2;
+                       container.items = new SimpleClass[2];
+                       container.items[0] = simple1;
+                       container.items[1] = simple2;
                        Serialize (container);
                        Assert.AreEqual (Infoset ("<ClassArrayContainer xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' ><items><SimpleClass><something>hello</something></SimpleClass><SimpleClass><something>hello</something></SimpleClass></items></ClassArrayContainer>"), WriterText);
                }
@@ -1204,7 +1216,7 @@ namespace MonoTests.System.XmlSerialization
                        Assert.AreEqual (Infoset ("<SimpleClass xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>hello</SimpleClass>"), WriterText, "#2");
 
                        try {
-                               attr.XmlText = new XmlTextAttribute (typeof (byte []));
+                               attr.XmlText = new XmlTextAttribute (typeof (byte[]));
                                Serialize (simple, overrides);
                                Assert.Fail ("#A1: XmlText.Type does not match the type it serializes: this should have failed");
                        } catch (InvalidOperationException ex) {
@@ -1310,8 +1322,8 @@ namespace MonoTests.System.XmlSerialization
                        overrides.Add (typeof (ClassArrayContainer), attr);
 
                        ClassArrayContainer container = new ClassArrayContainer ();
-                       container.items = new SimpleClass [1];
-                       container.items [0] = new SimpleClass ();
+                       container.items = new SimpleClass[1];
+                       container.items[0] = new SimpleClass ();
                        Serialize (container, overrides);
                        Assert.AreEqual (Infoset ("<simple xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' ><items><SimpleClass /></items></simple>"), WriterText);
 
@@ -1792,10 +1804,64 @@ namespace MonoTests.System.XmlSerialization
                public void TestSerializeXmlNodeArray ()
                {
                        XmlDocument doc = new XmlDocument ();
-                       Serialize (new XmlNode [] { doc.CreateAttribute ("at"), doc.CreateElement ("elem1"), doc.CreateElement ("elem2") }, typeof (object));
+                       Serialize (new XmlNode[] { doc.CreateAttribute ("at"), doc.CreateElement ("elem1"), doc.CreateElement ("elem2") }, typeof (object));
                        Assert.AreEqual (Infoset ("<anyType at=\"\"><elem1/><elem2/></anyType>"), WriterText);
                }
 
+               [Test]
+               public void TestSerializeXmlNodeArray2 ()
+               {
+                       XmlDocument doc = new XmlDocument ();
+                       Serialize (new XmlNode[] { doc.CreateElement ("elem1"), doc.CreateElement ("elem2") }, typeof (XmlNode []));
+                       Assert.AreEqual (Infoset (String.Format ("<ArrayOfXmlNode xmlns:xsd='{0}' xmlns:xsi='{1}'><XmlNode><elem1/></XmlNode><XmlNode><elem2/></XmlNode></ArrayOfXmlNode>", XmlSchema.Namespace, XmlSchema.InstanceNamespace)), WriterText);
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               [Category ("NotWorking")]
+               public void TestSerializeXmlNodeArrayIncludesAttribute ()
+               {
+                       XmlDocument doc = new XmlDocument ();
+                       Serialize (new XmlNode[] { doc.CreateAttribute ("at"), doc.CreateElement ("elem1"), doc.CreateElement ("elem2") }, typeof (XmlNode []));
+               }
+
+               [Test]
+               public void TestSerializeXmlElementArray ()
+               {
+                       XmlDocument doc = new XmlDocument ();
+                       Serialize (new XmlElement[] { doc.CreateElement ("elem1"), doc.CreateElement ("elem2") }, typeof (object));
+                       Assert.AreEqual (Infoset ("<anyType><elem1/><elem2/></anyType>"), WriterText);
+               }
+
+#if NET_2_0
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))] // List<XmlNode> is not supported
+               public void TestSerializeGenericListOfNode ()
+               {
+                       XmlDocument doc = new XmlDocument ();
+                       Serialize (new List<XmlNode> (new XmlNode [] { doc.CreateAttribute ("at"), doc.CreateElement ("elem1"), doc.CreateElement ("elem2") }), typeof (object));
+                       Assert.AreEqual (Infoset ("<anyType at=\"\"><elem1/><elem2/></anyType>"), WriterText);
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))] // List<XmlElement> is not supported
+               public void TestSerializeGenericListOfElement ()
+               {
+                       XmlDocument doc = new XmlDocument ();
+                       Serialize (new List<XmlElement> (new XmlElement [] { doc.CreateElement ("elem1"), doc.CreateElement ("elem2") }), typeof (object));
+                       Assert.AreEqual (Infoset ("<anyType><elem1/><elem2/></anyType>"), WriterText);
+               }
+#endif
+               [Test]
+               public void TestSerializeXmlDocument ()
+               {
+                       XmlDocument doc = new XmlDocument ();
+                       doc.LoadXml (@"<?xml version=""1.0"" encoding=""utf-8"" ?><root/>");
+                       Serialize (doc, typeof (XmlDocument));
+                       Assert.AreEqual ("<?xml version='1.0' encoding='utf-16'?><root />",
+                               sw.GetStringBuilder ().ToString ());
+               }
+
                [Test]
                public void TestSerializeXmlElement ()
                {
@@ -1869,6 +1935,15 @@ namespace MonoTests.System.XmlSerialization
                        Assert.AreEqual (Infoset ("<ReadOnlyProperties xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText);
                }
 
+               [Test]
+               public void TestSerializeReadOnlyListProp ()
+               {
+                       ReadOnlyListProperty ts = new ReadOnlyListProperty ();
+                       Serialize (ts);
+                       Assert.AreEqual (Infoset ("<ReadOnlyListProperty xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><StrList><string>listString1</string><string>listString2</string></StrList></ReadOnlyListProperty>"), WriterText);
+               }
+
+
                [Test]
                public void TestSerializeIList ()
                {
@@ -1893,10 +1968,9 @@ namespace MonoTests.System.XmlSerialization
                        tw.WriteEndElement ();
                }
 
-               [Test]
+               [Test] // bug #76049
                public void TestIncludeType ()
                {
-                       // Test for bug #76049
                        XmlReflectionImporter imp = new XmlReflectionImporter ();
                        XmlTypeMapping map = imp.ImportTypeMapping (typeof (object));
                        imp.IncludeType (typeof (TestSpace));
@@ -2107,8 +2181,7 @@ namespace MonoTests.System.XmlSerialization
                        Assert.AreEqual (Infoset (res), WriterText);
                }
 
-               // bug #78536
-               [Test]
+               [Test] // bug #78536
                public void CDataTextNodes ()
                {
                        XmlSerializer ser = new XmlSerializer (typeof (CDataTextNodesType));
@@ -2123,7 +2196,7 @@ namespace MonoTests.System.XmlSerialization
                        ser.Deserialize (new XmlTextReader (xml, XmlNodeType.Document, null));
                }
 
-#if NET_2_0
+#if !TARGET_JVM && !MOBILE
                [Test]
                public void GenerateSerializerGenerics ()
                {
@@ -2133,6 +2206,7 @@ namespace MonoTests.System.XmlSerialization
                                new Type [] {type},
                                new XmlTypeMapping [] {imp.ImportTypeMapping (type)});
                }
+#endif
 
                [Test]
                public void Nullable ()
@@ -2143,31 +2217,818 @@ namespace MonoTests.System.XmlSerialization
                        xtw = new XmlTextWriter (sw);
                        ser.Serialize (xtw, nullableType);
                        xtw.Close ();
-                       Assert.AreEqual ("<?xml version=\"1.0\" encoding=\"utf-16\"?><int>5</int>", sw.ToString ());
+                       string expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?><int>5</int>";
+                       Assert.AreEqual (Infoset (expected), WriterText);
                        int? i = (int?) ser.Deserialize (new StringReader (sw.ToString ()));
                        Assert.AreEqual (5, i);
                }
-#endif
+
+               [Test]
+               public void NullableEnums ()
+               {
+                       WithNulls w = new WithNulls ();
+                       XmlSerializer ser = new XmlSerializer (typeof(WithNulls));
+                       StringWriter tw = new StringWriter ();
+                       ser.Serialize (tw, w);
+
+                       string expected = "<?xml version='1.0' encoding='utf-16'?>" +
+                               "<WithNulls xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
+                                       "<nint xsi:nil='true' />" +
+                                       "<nenum xsi:nil='true' />" +
+                                       "<ndate xsi:nil='true' />" +
+                                       "</WithNulls>";
+                       
+                       Assert.AreEqual (Infoset (expected), Infoset (tw.ToString ()));
+                       
+                       StringReader sr = new StringReader (tw.ToString ());
+                       w = (WithNulls) ser.Deserialize (sr);
+                       
+                       Assert.IsFalse (w.nint.HasValue);
+                       Assert.IsFalse (w.nenum.HasValue);
+                       Assert.IsFalse (w.ndate.HasValue);
+                       
+                       DateTime t = new DateTime (2008,4,1);
+                       w.nint = 4;
+                       w.ndate = t;
+                       w.nenum = TestEnumWithNulls.bb;
+                       
+                       tw = new StringWriter ();
+                       ser.Serialize (tw, w);
+                       
+                       expected = "<?xml version='1.0' encoding='utf-16'?>" +
+                               "<WithNulls xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
+                                       "<nint>4</nint>" +
+                                       "<nenum>bb</nenum>" +
+                                       "<ndate>2008-04-01T00:00:00</ndate>" +
+                                       "</WithNulls>";
+                       
+                       Assert.AreEqual (Infoset (expected), Infoset (tw.ToString ()));
+                       
+                       sr = new StringReader (tw.ToString ());
+                       w = (WithNulls) ser.Deserialize (sr);
+                       
+                       Assert.IsTrue (w.nint.HasValue);
+                       Assert.IsTrue (w.nenum.HasValue);
+                       Assert.IsTrue (w.ndate.HasValue);
+                       Assert.AreEqual (4, w.nint.Value);
+                       Assert.AreEqual (TestEnumWithNulls.bb, w.nenum.Value);
+                       Assert.AreEqual (t, w.ndate.Value);
+               }
+
+               [Test]
+               public void SerializeBase64Binary()
+               {
+                       XmlSerializer ser = new XmlSerializer (typeof (Base64Binary));
+                       sw = new StringWriter ();
+                       XmlTextWriter xtw = new XmlTextWriter (sw);
+                       ser.Serialize (xtw, new Base64Binary ());
+                       xtw.Close ();
+                       string expected = @"<?xml version=""1.0"" encoding=""utf-16""?><Base64Binary xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" Data=""AQID"" />";
+                       Assert.AreEqual (Infoset (expected), WriterText);
+                       Base64Binary h = (Base64Binary) ser.Deserialize (new StringReader (sw.ToString ()));
+                       Assert.AreEqual (new byte [] {1, 2, 3}, h.Data);
+               }
 
                [Test] // bug #79989, #79990
-               public void SerializeHexBinary()
+               public void SerializeHexBinary ()
                {
                        XmlSerializer ser = new XmlSerializer (typeof (HexBinary));
-                       StringWriter sw = new StringWriter ();
+                       sw = new StringWriter ();
                        XmlTextWriter xtw = new XmlTextWriter (sw);
                        ser.Serialize (xtw, new HexBinary ());
                        xtw.Close ();
                        string expected = @"<?xml version=""1.0"" encoding=""utf-16""?><HexBinary xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" Data=""010203"" />";
-                       Assert.AreEqual (expected, sw.ToString ());
+                       Assert.AreEqual (Infoset (expected), WriterText);
                        HexBinary h = (HexBinary) ser.Deserialize (new StringReader (sw.ToString ()));
-                       Assert.AreEqual (new byte [] {1, 2, 3}, h.Data);
+                       Assert.AreEqual (new byte[] { 1, 2, 3 }, h.Data);
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void XmlArrayAttributeOnInt ()
+               {
+                       new XmlSerializer (typeof (XmlArrayOnInt));
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void XmlArrayAttributeUnqualifiedWithNamespace ()
+               {
+                       new XmlSerializer (typeof (XmlArrayUnqualifiedWithNamespace));
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void XmlArrayItemAttributeUnqualifiedWithNamespace ()
+               {
+                       new XmlSerializer (typeof (XmlArrayItemUnqualifiedWithNamespace));
+               }
+
+               [Test] // bug #78042
+               public void XmlArrayAttributeOnArray ()
+               {
+                       XmlSerializer ser = new XmlSerializer (typeof (XmlArrayOnArray));
+                       sw = new StringWriter ();
+                       XmlTextWriter xtw = new XmlTextWriter (sw);
+                       ser.Serialize (xtw, new XmlArrayOnArray ());
+                       xtw.Close ();
+                       string expected = @"<?xml version=""1.0"" encoding=""utf-16""?><XmlArrayOnArray xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""urn:foo""><Sane xmlns=""""><string xmlns=""urn:foo"">foo</string><string xmlns=""urn:foo"">bar</string></Sane><Mids xmlns=""""><ArrayItemInXmlArray xmlns=""urn:foo""><Whee xmlns=""""><string xmlns=""urn:gyabo"">foo</string><string xmlns=""urn:gyabo"">bar</string></Whee></ArrayItemInXmlArray></Mids></XmlArrayOnArray>";
+                       Assert.AreEqual (Infoset (expected), WriterText);
+               }
+
+               [Test]
+               public void XmlArrayAttributeOnCollection ()
+               {
+                       XmlSerializer ser = new XmlSerializer (typeof (XmlArrayOnArrayList));
+                       XmlArrayOnArrayList inst = new XmlArrayOnArrayList ();
+                       inst.Sane.Add ("abc");
+                       inst.Sane.Add (1);
+                       sw = new StringWriter ();
+                       XmlTextWriter xtw = new XmlTextWriter (sw);
+                       ser.Serialize (xtw, inst);
+                       xtw.Close ();
+                       string expected = @"<?xml version=""1.0"" encoding=""utf-16""?><XmlArrayOnArrayList xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""urn:foo""><Sane xmlns=""""><anyType xsi:type=""xsd:string"" xmlns=""urn:foo"">abc</anyType><anyType xsi:type=""xsd:int"" xmlns=""urn:foo"">1</anyType></Sane></XmlArrayOnArrayList>";
+                       Assert.AreEqual (Infoset (expected), WriterText);
+               }
+
+               [Test] // bug #338705
+               public void SerializeTimeSpan ()
+               {
+                       // TimeSpan itself is not for duration. Hence it is just regarded as one of custom types.
+                       XmlSerializer ser = new XmlSerializer (typeof (TimeSpan));
+                       ser.Serialize (TextWriter.Null, TimeSpan.Zero);
+               }
+
+               [Test]
+               public void SerializeDurationToString ()
+               {
+                       XmlSerializer ser = new XmlSerializer (typeof (TimeSpanContainer1));
+                       ser.Serialize (TextWriter.Null, new TimeSpanContainer1 ());
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void SerializeDurationToTimeSpan ()
+               {
+                       XmlSerializer ser = new XmlSerializer (typeof (TimeSpanContainer2));
+                       ser.Serialize (TextWriter.Null, new TimeSpanContainer2 ());
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void SerializeInvalidDataType ()
+               {
+                       XmlSerializer ser = new XmlSerializer (typeof (InvalidTypeContainer));
+                       ser.Serialize (TextWriter.Null, new InvalidTypeContainer ());
+               }
+
+               [Test]
+#if !NET_2_0
+               [ExpectedException (typeof (ApplicationException))]
+#endif
+               public void SerializeErrorneousIXmlSerializable ()
+               {
+                       Serialize (new ErrorneousGetSchema ());
+                       Assert.AreEqual ("<:ErrorneousGetSchema></>", Infoset (sw.ToString ()));
+               }
+
+#if NET_2_0
+               public void DateTimeRoundtrip ()
+               {
+                       // bug #337729
+                       XmlSerializer ser = new XmlSerializer (typeof (DateTime));
+                       StringWriter sw = new StringWriter ();
+                       ser.Serialize (sw, DateTime.UtcNow);
+                       DateTime d = (DateTime) ser.Deserialize (new StringReader (sw.ToString ()));
+                       Assert.AreEqual (DateTimeKind.Utc, d.Kind);
+               }
+#endif
+
+               [Test]
+               public void SupportIXmlSerializableImplicitlyConvertible ()
+               {
+                       XmlAttributes attrs = new XmlAttributes ();
+                       XmlElementAttribute attr = new XmlElementAttribute ();
+                       attr.ElementName = "XmlSerializable";
+                       attr.Type = typeof (XmlSerializableImplicitConvertible.XmlSerializable);
+                       attrs.XmlElements.Add (attr);
+                       XmlAttributeOverrides attrOverrides = new
+                       XmlAttributeOverrides ();
+                       attrOverrides.Add (typeof (XmlSerializableImplicitConvertible), "B", attrs);
+
+                       XmlSerializableImplicitConvertible x = new XmlSerializableImplicitConvertible ();
+                       new XmlSerializer (typeof (XmlSerializableImplicitConvertible), attrOverrides).Serialize (TextWriter.Null, x);
+               }
+
+               [Test] // bug #566370
+               public void SerializeEnumWithCSharpKeyword ()
+               {
+                       var ser = new XmlSerializer (typeof (DoxCompoundKind));
+                       for (int i = 0; i < 100; i++) // test serialization code generator
+                               ser.Serialize (Console.Out, DoxCompoundKind.@class);
+               }
+
+               public enum DoxCompoundKind
+               {
+                       [XmlEnum("class")]
+                       @class,
+                       [XmlEnum("struct")]
+                       @struct,
+                       union,
+                       [XmlEnum("interface")]
+                       @interface,
+                       protocol,
+                       category,
+                       exception,
+                       file,
+                       [XmlEnum("namespace")]
+                       @namespace,
+                       group,
+                       page,
+                       example,
+                       dir
+               }
+
+               #region GenericsSeralizationTests
+
+#if NET_2_0
+               [Test]
+               public void TestSerializeGenSimpleClassString ()
+               {
+                       GenSimpleClass<string> simple = new GenSimpleClass<string> ();
+                       Serialize (simple);
+                       Assert.AreEqual (Infoset ("<GenSimpleClassOfString xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' />"), WriterText);
+
+                       simple.something = "hello";
+
+                       Serialize (simple);
+                       Assert.AreEqual (Infoset ("<GenSimpleClassOfString xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>hello</something></GenSimpleClassOfString>"), WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenSimpleClassBool ()
+               {
+                       GenSimpleClass<bool> simple = new GenSimpleClass<bool> ();
+                       Serialize (simple);
+                       Assert.AreEqual (Infoset ("<GenSimpleClassOfBoolean xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>false</something></GenSimpleClassOfBoolean>"), WriterText);
+
+                       simple.something = true;
+
+                       Serialize (simple);
+                       Assert.AreEqual (Infoset ("<GenSimpleClassOfBoolean xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>true</something></GenSimpleClassOfBoolean>"), WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenSimpleStructInt ()
+               {
+                       GenSimpleStruct<int> simple = new GenSimpleStruct<int> (0);
+                       Serialize (simple);
+                       Assert.AreEqual (Infoset ("<GenSimpleStructOfInt32 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>0</something></GenSimpleStructOfInt32>"), WriterText);
+
+                       simple.something = 123;
+
+                       Serialize (simple);
+                       Assert.AreEqual (Infoset ("<GenSimpleStructOfInt32 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something>123</something></GenSimpleStructOfInt32>"), WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenListClassString ()
+               {
+                       GenListClass<string> genlist = new GenListClass<string> ();
+                       Serialize (genlist);
+                       Assert.AreEqual (Infoset ("<GenListClassOfString xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><somelist></somelist></GenListClassOfString>"), WriterText);
+
+                       genlist.somelist.Add ("Value1");
+                       genlist.somelist.Add ("Value2");
+
+                       Serialize (genlist);
+                       Assert.AreEqual (Infoset ("<GenListClassOfString xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><somelist><string>Value1</string><string>Value2</string></somelist></GenListClassOfString>"), WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenListClassFloat ()
+               {
+                       GenListClass<float> genlist = new GenListClass<float> ();
+                       Serialize (genlist);
+                       Assert.AreEqual (Infoset ("<GenListClassOfSingle xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><somelist></somelist></GenListClassOfSingle>"), WriterText);
+
+                       genlist.somelist.Add (1);
+                       genlist.somelist.Add (2.2F);
+
+                       Serialize (genlist);
+                       Assert.AreEqual (Infoset ("<GenListClassOfSingle xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><somelist><float>1</float><float>2.2</float></somelist></GenListClassOfSingle>"), WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenListClassList ()
+               {
+                       GenListClass<GenListClass<int>> genlist = new GenListClass<GenListClass<int>> ();
+                       Serialize (genlist);
+                       Assert.AreEqual (Infoset ("<GenListClassOfGenListClassOfInt32 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><somelist></somelist></GenListClassOfGenListClassOfInt32>"), WriterText);
+
+                       GenListClass<int> inlist1 = new GenListClass<int> ();
+                       inlist1.somelist.Add (1);
+                       inlist1.somelist.Add (2);
+                       GenListClass<int> inlist2 = new GenListClass<int> ();
+                       inlist2.somelist.Add (10);
+                       inlist2.somelist.Add (20);
+                       genlist.somelist.Add (inlist1);
+                       genlist.somelist.Add (inlist2);
+
+                       Serialize (genlist);
+                       Assert.AreEqual (Infoset ("<GenListClassOfGenListClassOfInt32 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><somelist><GenListClassOfInt32><somelist><int>1</int><int>2</int></somelist></GenListClassOfInt32><GenListClassOfInt32><somelist><int>10</int><int>20</int></somelist></GenListClassOfInt32></somelist></GenListClassOfGenListClassOfInt32>"), WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenListClassArray ()
+               {
+                       GenListClass<GenArrayClass<char>> genlist = new GenListClass<GenArrayClass<char>> ();
+                       Serialize (genlist);
+                       Assert.AreEqual (Infoset ("<GenListClassOfGenArrayClassOfChar xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><somelist></somelist></GenListClassOfGenArrayClassOfChar>"), WriterText);
+
+                       GenArrayClass<char> genarr1 = new GenArrayClass<char> ();
+                       genarr1.arr[0] = 'a';
+                       genarr1.arr[1] = 'b';
+                       genlist.somelist.Add (genarr1);
+                       GenArrayClass<char> genarr2 = new GenArrayClass<char> ();
+                       genarr2.arr[0] = 'd';
+                       genarr2.arr[1] = 'e';
+                       genarr2.arr[2] = 'f';
+                       genlist.somelist.Add (genarr2);
+
+                       Serialize (genlist);
+                       Assert.AreEqual (Infoset ("<GenListClassOfGenArrayClassOfChar xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><somelist><GenArrayClassOfChar><arr><char>97</char><char>98</char><char>0</char></arr></GenArrayClassOfChar><GenArrayClassOfChar><arr><char>100</char><char>101</char><char>102</char></arr></GenArrayClassOfChar></somelist></GenListClassOfGenArrayClassOfChar>"), WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenTwoClassCharDouble ()
+               {
+                       GenTwoClass<char, double> gentwo = new GenTwoClass<char, double> ();
+                       Serialize (gentwo);
+                       Assert.AreEqual (Infoset ("<GenTwoClassOfCharDouble xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something1>0</something1><something2>0</something2></GenTwoClassOfCharDouble>"), WriterText);
+
+                       gentwo.something1 = 'a';
+                       gentwo.something2 = 2.2;
+
+                       Serialize (gentwo);
+                       Assert.AreEqual (Infoset ("<GenTwoClassOfCharDouble xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something1>97</something1><something2>2.2</something2></GenTwoClassOfCharDouble>"), WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenDerivedClassDecimalShort ()
+               {
+                       GenDerivedClass<decimal, short> derived = new GenDerivedClass<decimal, short> ();
+                       Serialize (derived);
+                       Assert.AreEqual (Infoset ("<GenDerivedClassOfDecimalInt16 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something2>0</something2><another1>0</another1><another2>0</another2></GenDerivedClassOfDecimalInt16>"), WriterText);
+
+                       derived.something1 = "Value1";
+                       derived.something2 = 1;
+                       derived.another1 = 1.1M;
+                       derived.another2 = -22;
+
+                       Serialize (derived);
+                       Assert.AreEqual (Infoset ("<GenDerivedClassOfDecimalInt16 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something1>Value1</something1><something2>1</something2><another1>1.1</another1><another2>-22</another2></GenDerivedClassOfDecimalInt16>"), WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenDerivedSecondClassByteUlong ()
+               {
+                       GenDerived2Class<byte, ulong> derived2 = new GenDerived2Class<byte, ulong> ();
+                       Serialize (derived2);
+                       Assert.AreEqual (Infoset ("<GenDerived2ClassOfByteUInt64 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something1>0</something1><something2>0</something2><another1>0</another1><another2>0</another2></GenDerived2ClassOfByteUInt64>"), WriterText);
+
+                       derived2.something1 = 1;
+                       derived2.something2 = 222;
+                       derived2.another1 = 111;
+                       derived2.another2 = 222222;
+
+                       Serialize (derived2);
+                       Assert.AreEqual (Infoset ("<GenDerived2ClassOfByteUInt64 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><something1>1</something1><something2>222</something2><another1>111</another1><another2>222222</another2></GenDerived2ClassOfByteUInt64>"), WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenNestedClass ()
+               {
+                       GenNestedClass<string, int>.InnerClass<bool> nested =
+                               new GenNestedClass<string, int>.InnerClass<bool> ();
+                       Serialize (nested);
+                       Assert.AreEqual (Infoset ("<InnerClassOfStringInt32Boolean xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><inner>0</inner><something>false</something></InnerClassOfStringInt32Boolean>"), WriterText);
+
+                       nested.inner = 5;
+                       nested.something = true;
+
+                       Serialize (nested);
+                       Assert.AreEqual (Infoset ("<InnerClassOfStringInt32Boolean xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><inner>5</inner><something>true</something></InnerClassOfStringInt32Boolean>"), WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenListClassListNested ()
+               {
+                       GenListClass<GenListClass<GenNestedClass<int, int>.InnerClass<string>>> genlist =
+                               new GenListClass<GenListClass<GenNestedClass<int, int>.InnerClass<string>>> ();
+                       Serialize (genlist);
+                       Assert.AreEqual (Infoset ("<GenListClassOfGenListClassOfInnerClassOfInt32Int32String xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><somelist></somelist></GenListClassOfGenListClassOfInnerClassOfInt32Int32String>"), WriterText);
+
+                       GenListClass<GenNestedClass<int, int>.InnerClass<string>> inlist1 =
+                               new GenListClass<GenNestedClass<int, int>.InnerClass<string>> ();
+                       GenNestedClass<int, int>.InnerClass<string> inval1 = new GenNestedClass<int, int>.InnerClass<string> ();
+                       inval1.inner = 1;
+                       inval1.something = "ONE";
+                       inlist1.somelist.Add (inval1);
+                       GenNestedClass<int, int>.InnerClass<string> inval2 = new GenNestedClass<int, int>.InnerClass<string> ();
+                       inval2.inner = 2;
+                       inval2.something = "TWO";
+                       inlist1.somelist.Add (inval2);
+                       GenListClass<GenNestedClass<int, int>.InnerClass<string>> inlist2 =
+                               new GenListClass<GenNestedClass<int, int>.InnerClass<string>> ();
+                       GenNestedClass<int, int>.InnerClass<string> inval3 = new GenNestedClass<int, int>.InnerClass<string> ();
+                       inval3.inner = 30;
+                       inval3.something = "THIRTY";
+                       inlist2.somelist.Add (inval3);
+                       genlist.somelist.Add (inlist1);
+                       genlist.somelist.Add (inlist2);
+
+                       Serialize (genlist);
+                       Assert.AreEqual (Infoset ("<GenListClassOfGenListClassOfInnerClassOfInt32Int32String xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><somelist><GenListClassOfInnerClassOfInt32Int32String><somelist><InnerClassOfInt32Int32String><inner>1</inner><something>ONE</something></InnerClassOfInt32Int32String><InnerClassOfInt32Int32String><inner>2</inner><something>TWO</something></InnerClassOfInt32Int32String></somelist></GenListClassOfInnerClassOfInt32Int32String><GenListClassOfInnerClassOfInt32Int32String><somelist><InnerClassOfInt32Int32String><inner>30</inner><something>THIRTY</something></InnerClassOfInt32Int32String></somelist></GenListClassOfInnerClassOfInt32Int32String></somelist></GenListClassOfGenListClassOfInnerClassOfInt32Int32String>"), WriterText);
+               }
+
+               public enum Myenum { one, two, three, four, five, six };
+               [Test]
+               public void TestSerializeGenArrayClassEnum ()
+               {
+                       GenArrayClass<Myenum> genarr = new GenArrayClass<Myenum> ();
+                       Serialize (genarr);
+                       Assert.AreEqual (Infoset ("<GenArrayClassOfMyenum xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><arr><Myenum>one</Myenum><Myenum>one</Myenum><Myenum>one</Myenum></arr></GenArrayClassOfMyenum>"), WriterText);
+
+                       genarr.arr[0] = Myenum.one;
+                       genarr.arr[1] = Myenum.three;
+                       genarr.arr[2] = Myenum.five;
+
+                       Serialize (genarr);
+                       Assert.AreEqual (Infoset ("<GenArrayClassOfMyenum xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><arr><Myenum>one</Myenum><Myenum>three</Myenum><Myenum>five</Myenum></arr></GenArrayClassOfMyenum>"), WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenArrayStruct ()
+               {
+                       GenArrayClass<GenSimpleStruct<uint>> genarr = new GenArrayClass<GenSimpleStruct<uint>> ();
+                       Serialize (genarr);
+                       Assert.AreEqual ("<:GenArrayClassOfGenSimpleStructOfUInt32 http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:arr><:GenSimpleStructOfUInt32><:something>0</></><:GenSimpleStructOfUInt32><:something>0</></><:GenSimpleStructOfUInt32><:something>0</></></></>", WriterText);
+
+                       GenSimpleStruct<uint> genstruct = new GenSimpleStruct<uint> ();
+                       genstruct.something = 111;
+                       genarr.arr[0] = genstruct;
+                       genstruct.something = 222;
+                       genarr.arr[1] = genstruct;
+                       genstruct.something = 333;
+                       genarr.arr[2] = genstruct;
+
+                       Serialize (genarr);
+                       Assert.AreEqual ("<:GenArrayClassOfGenSimpleStructOfUInt32 http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:arr><:GenSimpleStructOfUInt32><:something>111</></><:GenSimpleStructOfUInt32><:something>222</></><:GenSimpleStructOfUInt32><:something>333</></></></>", WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenArrayList ()
+               {
+                       GenArrayClass<GenListClass<string>> genarr = new GenArrayClass<GenListClass<string>> ();
+                       Serialize (genarr);
+                       Assert.AreEqual ("<:GenArrayClassOfGenListClassOfString http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:arr><:GenListClassOfString http://www.w3.org/2001/XMLSchema-instance:nil='true'></><:GenListClassOfString http://www.w3.org/2001/XMLSchema-instance:nil='true'></><:GenListClassOfString http://www.w3.org/2001/XMLSchema-instance:nil='true'></></></>", WriterText);
+
+                       GenListClass<string> genlist1 = new GenListClass<string> ();
+                       genlist1.somelist.Add ("list1-val1");
+                       genlist1.somelist.Add ("list1-val2");
+                       genarr.arr[0] = genlist1;
+                       GenListClass<string> genlist2 = new GenListClass<string> ();
+                       genlist2.somelist.Add ("list2-val1");
+                       genlist2.somelist.Add ("list2-val2");
+                       genlist2.somelist.Add ("list2-val3");
+                       genlist2.somelist.Add ("list2-val4");
+                       genarr.arr[1] = genlist2;
+                       GenListClass<string> genlist3 = new GenListClass<string> ();
+                       genlist3.somelist.Add ("list3val");
+                       genarr.arr[2] = genlist3;
+
+                       Serialize (genarr);
+                       Assert.AreEqual ("<:GenArrayClassOfGenListClassOfString http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:arr><:GenListClassOfString><:somelist><:string>list1-val1</><:string>list1-val2</></></><:GenListClassOfString><:somelist><:string>list2-val1</><:string>list2-val2</><:string>list2-val3</><:string>list2-val4</></></><:GenListClassOfString><:somelist><:string>list3val</></></></></>", WriterText);
+               }
+
+               [Test]
+               public void TestSerializeGenComplexStruct ()
+               {
+                       GenComplexStruct<int, string> complex = new GenComplexStruct<int, string> (0);
+                       Serialize (complex);
+                       Assert.AreEqual ("<:GenComplexStructOfInt32String http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:something>0</><:simpleclass><:something>0</></><:simplestruct><:something>0</></><:listclass><:somelist></></><:arrayclass><:arr><:int>0</><:int>0</><:int>0</></></><:twoclass><:something1>0</></><:derivedclass><:something2>0</><:another1>0</></><:derived2><:something1>0</><:another1>0</></><:nestedouter><:outer>0</></><:nestedinner><:something>0</></></>", WriterText);
+
+                       complex.something = 123;
+                       complex.simpleclass.something = 456;
+                       complex.simplestruct.something = 789;
+                       GenListClass<int> genlist = new GenListClass<int> ();
+                       genlist.somelist.Add (100);
+                       genlist.somelist.Add (200);
+                       complex.listclass = genlist;
+                       GenArrayClass<int> genarr = new GenArrayClass<int> ();
+                       genarr.arr[0] = 11;
+                       genarr.arr[1] = 22;
+                       genarr.arr[2] = 33;
+                       complex.arrayclass = genarr;
+                       complex.twoclass.something1 = 10;
+                       complex.twoclass.something2 = "Ten";
+                       complex.derivedclass.another1 = 1;
+                       complex.derivedclass.another2 = "one";
+                       complex.derivedclass.something1 = "two";
+                       complex.derivedclass.something2 = 2;
+                       complex.derived2.another1 = 3;
+                       complex.derived2.another2 = "three";
+                       complex.derived2.something1 = 4;
+                       complex.derived2.something2 = "four";
+                       complex.nestedouter.outer = 5;
+                       complex.nestedinner.inner = "six";
+                       complex.nestedinner.something = 6;
+
+                       Serialize (complex);
+                       Assert.AreEqual ("<:GenComplexStructOfInt32String http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:something>123</><:simpleclass><:something>456</></><:simplestruct><:something>789</></><:listclass><:somelist><:int>100</><:int>200</></></><:arrayclass><:arr><:int>11</><:int>22</><:int>33</></></><:twoclass><:something1>10</><:something2>Ten</></><:derivedclass><:something1>two</><:something2>2</><:another1>1</><:another2>one</></><:derived2><:something1>4</><:something2>four</><:another1>3</><:another2>three</></><:nestedouter><:outer>5</></><:nestedinner><:inner>six</><:something>6</></></>", WriterText);
+               }
+
+               [Test] // bug #80759
+               public void HasNullableField ()
+               {
+                       Bug80759 foo = new Bug80759 ();
+                       foo.Test = "BAR";
+                       foo.NullableInt = 10;
+
+                       XmlSerializer serializer = new XmlSerializer (typeof (Bug80759));
+
+                       MemoryStream stream = new MemoryStream ();
+
+                       serializer.Serialize (stream, foo);
+                       stream.Position = 0;
+                       foo = (Bug80759) serializer.Deserialize (stream);
+               }
+
+               [Test] // bug #80759, with fieldSpecified.
+               [ExpectedException (typeof (InvalidOperationException))]
+               [Category ("NotWorking")]
+               public void HasFieldSpecifiedButIrrelevant ()
+               {
+                       Bug80759_2 foo = new Bug80759_2 ();
+                       foo.Test = "BAR";
+                       foo.NullableInt = 10;
+
+                       XmlSerializer serializer = new XmlSerializer (typeof (Bug80759_2));
+
+                       MemoryStream stream = new MemoryStream ();
+
+                       serializer.Serialize (stream, foo);
+                       stream.Position = 0;
+                       foo = (Bug80759_2) serializer.Deserialize (stream);
+               }
+
+               [Test]
+               public void HasNullableField2 ()
+               {
+                       Bug80759 foo = new Bug80759 ();
+                       foo.Test = "BAR";
+                       foo.NullableInt = 10;
+
+                       XmlSerializer serializer = new XmlSerializer (typeof (Bug80759));
+
+                       MemoryStream stream = new MemoryStream ();
+
+                       serializer.Serialize (stream, foo);
+                       stream.Position = 0;
+                       foo = (Bug80759) serializer.Deserialize (stream);
+
+                       Assert.AreEqual ("BAR", foo.Test, "#1");
+                       Assert.AreEqual (10, foo.NullableInt, "#2");
+
+                       foo.NullableInt = null;
+                       stream = new MemoryStream ();
+                       serializer.Serialize (stream, foo);
+                       stream.Position = 0;
+                       foo = (Bug80759) serializer.Deserialize (stream);
+
+                       Assert.AreEqual ("BAR", foo.Test, "#3");
+                       Assert.IsNull (foo.NullableInt, "#4");
+               }
+
+               [Test]
+               public void SupportPrivateCtorOnly ()
+               {
+                       XmlSerializer xs =
+                               new XmlSerializer (typeof (PrivateCtorOnly));
+                       StringWriter sw = new StringWriter ();
+                       xs.Serialize (sw, PrivateCtorOnly.Instance);
+                       xs.Deserialize (new StringReader (sw.ToString ()));
+               }
+
+               [Test]
+               public void XmlSchemaProviderQNameBecomesRootName ()
+               {
+                       xs = new XmlSerializer (typeof (XmlSchemaProviderQNameBecomesRootNameType));
+                       Serialize (new XmlSchemaProviderQNameBecomesRootNameType ());
+                       Assert.AreEqual (Infoset ("<foo />"), WriterText);
+                       xs.Deserialize (new StringReader ("<foo/>"));
+               }
+
+               [Test]
+               public void XmlSchemaProviderQNameBecomesRootName2 ()
+               {
+                       string xml = "<XmlSchemaProviderQNameBecomesRootNameType2 xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Foo><foo /></Foo></XmlSchemaProviderQNameBecomesRootNameType2>";
+                       xs = new XmlSerializer (typeof (XmlSchemaProviderQNameBecomesRootNameType2));
+                       Serialize (new XmlSchemaProviderQNameBecomesRootNameType2 ());
+                       Assert.AreEqual (Infoset (xml), WriterText);
+                       xs.Deserialize (new StringReader (xml));
+               }
+
+               [Test]
+               public void XmlAnyElementForObjects () // bug #553032
+               {
+                       new XmlSerializer (typeof (XmlAnyElementForObjectsType));
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void XmlAnyElementForObjects2 () // bug #553032-2
+               {
+                       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 ()
+               {
+                       var obj = new XmlRootOverridesSchemaProviderQNameType ();
+
+                       XmlSerializer xs = new XmlSerializer (obj.GetType ());
+
+                       var sw = new StringWriter ();
+                       using (XmlWriter xw = XmlWriter.Create (sw))
+                               xs.Serialize (xw, obj);
+                       Assert.IsTrue (sw.ToString ().IndexOf ("foo") > 0, "#1");
+               }
+
+               public class AnotherArrayListType
+               {
+                       [XmlAttribute]
+                       public string one = "aaa";
+                       [XmlAttribute]
+                       public string another = "bbb";
+               }
+
+               public class DerivedArrayListType : AnotherArrayListType
+               {
+
+               }
+
+               public class ClassWithArrayList
+               {
+                       [XmlElement (Type = typeof(int), ElementName = "int_elem")]
+                       [XmlElement (Type = typeof(string), ElementName = "string_elem")]
+                       [XmlElement (Type = typeof(AnotherArrayListType), ElementName = "another_elem")]
+                       [XmlElement (Type = typeof(DerivedArrayListType), ElementName = "derived_elem")]
+                       public ArrayList list;
+               }
+
+               public class ClassWithArray
+               {
+                       [XmlElement (Type = typeof(int), ElementName = "int_elem")]
+                       [XmlElement (Type = typeof(string), ElementName = "string_elem")]
+                       [XmlElement (Type = typeof(AnotherArrayListType), ElementName = "another_elem")]
+                       [XmlElement (Type = typeof(DerivedArrayListType), ElementName = "derived_elem")]
+                       public object[] list;
+
+               }
+
+               [Test]
+               public void MultipleXmlElementAttributesOnArrayList()
+               {
+                       var test = new ClassWithArrayList();
+
+                       test.list = new ArrayList();
+                       test.list.Add(3);
+                       test.list.Add("apepe");
+                       test.list.Add(new AnotherArrayListType());
+                       test.list.Add(new DerivedArrayListType());
+
+                       Serialize(test);
+                       var expected_text = "<:ClassWithArrayList http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:int_elem>3</><:string_elem>apepe</><:another_elem :another='bbb' :one='aaa'></><:derived_elem :another='bbb' :one='aaa'></></>";
+
+                       Assert.AreEqual(WriterText, expected_text, WriterText);
+               }
+
+               [Test]
+               public void MultipleXmlElementAttributesOnArray()
+               {
+                       var test = new ClassWithArray();
+
+                       test.list = new object[] { 3, "apepe", new AnotherArrayListType(), new DerivedArrayListType() };
+
+                       Serialize(test);
+                       var expected_text = "<:ClassWithArray http://www.w3.org/2000/xmlns/:xsd='http://www.w3.org/2001/XMLSchema' http://www.w3.org/2000/xmlns/:xsi='http://www.w3.org/2001/XMLSchema-instance'><:int_elem>3</><:string_elem>apepe</><:another_elem :another='bbb' :one='aaa'></><:derived_elem :another='bbb' :one='aaa'></></>";
+
+                       Assert.AreEqual(WriterText, expected_text, WriterText);
+               }
+
+#endif
+
+               #endregion //GenericsSeralizationTests
+
+               public class XmlArrayOnInt
+               {
+                       [XmlArray]
+                       public int Bogus;
+               }
+
+               public class XmlArrayUnqualifiedWithNamespace
+               {
+                       [XmlArray (Namespace = "", Form = XmlSchemaForm.Unqualified)]
+                       public ArrayList Sane = new ArrayList ();
+               }
+
+               public class XmlArrayItemUnqualifiedWithNamespace
+               {
+                       [XmlArrayItem ("foo", Namespace = "", Form = XmlSchemaForm.Unqualified)]
+                       public ArrayList Sane = new ArrayList ();
+               }
+
+               [XmlRoot (Namespace = "urn:foo")]
+               public class XmlArrayOnArrayList
+               {
+                       [XmlArray (Form = XmlSchemaForm.Unqualified)]
+                       public ArrayList Sane = new ArrayList ();
+               }
+
+               [XmlRoot (Namespace = "urn:foo")]
+               public class XmlArrayOnArray
+               {
+                       [XmlArray (Form = XmlSchemaForm.Unqualified)]
+                       public string[] Sane = new string[] { "foo", "bar" };
+
+                       [XmlArray (Form = XmlSchemaForm.Unqualified)]
+                       public ArrayItemInXmlArray[] Mids =
+                               new ArrayItemInXmlArray[] { new ArrayItemInXmlArray () };
+               }
+
+               [XmlType (Namespace = "urn:gyabo")]
+               public class ArrayItemInXmlArray
+               {
+                       [XmlArray (Form = XmlSchemaForm.Unqualified)]
+                       public string[] Whee = new string[] { "foo", "bar" };
+               }
+
+               [XmlRoot ("Base64Binary")]
+               public class Base64Binary
+               {
+                       [XmlAttribute (DataType = "base64Binary")]
+                       public byte [] Data = new byte [] {1, 2, 3};
                }
 
                [XmlRoot ("HexBinary")]
                public class HexBinary
                {
                        [XmlAttribute (DataType = "hexBinary")]
-                       public byte [] Data = new byte [] {1, 2, 3};
+                       public byte[] Data = new byte[] { 1, 2, 3 };
+               }
+
+               [XmlRoot ("PrivateCtorOnly")]
+               public class PrivateCtorOnly
+               {
+                       public static PrivateCtorOnly Instance = new PrivateCtorOnly ();
+                       private PrivateCtorOnly ()
+                       {
+                       }
                }
 
                public class CDataTextNodesType
@@ -2181,6 +3042,112 @@ namespace MonoTests.System.XmlSerialization
                        public string Value;
                }
 
+               public class InvalidTypeContainer
+               {
+                       [XmlElement (DataType = "invalid")]
+                       public string InvalidTypeItem = "aaa";
+               }
+
+               public class TimeSpanContainer1
+               {
+                       [XmlElement (DataType = "duration")]
+                       public string StringDuration = "aaa";
+               }
+
+               public class TimeSpanContainer2
+               {
+                       [XmlElement (DataType = "duration")]
+                       public TimeSpan StringDuration = TimeSpan.FromSeconds (1);
+               }
+
+#if NET_2_0
+               public class Bug80759
+               {
+                       public string Test;
+                       public int? NullableInt;
+               }
+
+               public class Bug80759_2
+               {
+                       public string Test;
+                       public int? NullableInt;
+
+                       [XmlIgnore]
+                       public bool NullableIntSpecified {
+                               get { return NullableInt.HasValue; }
+                       }
+               }
+
+               [XmlSchemaProvider ("GetXsdType")]
+               public class XmlSchemaProviderQNameBecomesRootNameType : IXmlSerializable
+               {
+                       public XmlSchema GetSchema ()
+                       {
+                               return null;
+                       }
+
+                       public void ReadXml (XmlReader reader)
+                       {
+                               reader.Skip ();
+                       }
+
+                       public void WriteXml (XmlWriter writer)
+                       {
+                       }
+
+                       public static XmlQualifiedName GetXsdType (XmlSchemaSet xss)
+                       {
+                               if (xss.Count == 0) {
+                                       XmlSchema xs = new XmlSchema ();
+                                       XmlSchemaComplexType ct = new XmlSchemaComplexType ();
+                                       ct.Name = "foo";
+                                       xs.Items.Add (ct);
+                                       xss.Add (xs);
+                               }
+                               return new XmlQualifiedName ("foo");
+                       }
+               }
+
+               public class XmlSchemaProviderQNameBecomesRootNameType2
+               {
+                       [XmlArrayItem (typeof (XmlSchemaProviderQNameBecomesRootNameType))]
+                       public object [] Foo = new object [] {new XmlSchemaProviderQNameBecomesRootNameType ()};
+               }
+
+               public class XmlAnyElementForObjectsType
+               {
+                       [XmlAnyElement]
+                       public object [] arr = new object [] {3,4,5};
+               }
+
+               [XmlRoot ("foo")]
+               [XmlSchemaProvider ("GetSchema")]
+               public class XmlRootOverridesSchemaProviderQNameType : IXmlSerializable
+               {
+                       public static XmlQualifiedName GetSchema (XmlSchemaSet xss)
+                       {
+                               var xs = new XmlSchema ();
+                               var xse = new XmlSchemaComplexType () { Name = "bar" };
+                               xs.Items.Add (xse);
+                               xss.Add (xs);
+                               return new XmlQualifiedName ("bar");
+                       }
+
+                       XmlSchema IXmlSerializable.GetSchema ()
+                       {
+                               return null;
+                       }
+
+                       void IXmlSerializable.ReadXml (XmlReader reader)
+                       {
+                       }
+                       void IXmlSerializable.WriteXml (XmlWriter writer)
+                       {
+                       }
+               }
+
+#endif
+
                void CDataTextNodes_BadNode (object s, XmlNodeEventArgs e)
                {
                        Assert.Fail ();
@@ -2223,8 +3190,8 @@ namespace MonoTests.System.XmlSerialization
                                ats.Sort ();
 
                                foreach (string name in ats) {
-                                       string [] nn = name.Split (' ');
-                                       GetInfoset (elem.Attributes [nn [0], nn [1]], sb);
+                                       string[] nn = name.Split (' ');
+                                       GetInfoset (elem.Attributes[nn[0], nn[1]], sb);
                                }
 
                                sb.Append (">");