[Mono-bugs] [Bug 61464][Cos] New - MS XmlSerializer can serialize ArrayList derived class with no public parameterless constructor, while Mono implementation cannot
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Tue, 13 Jul 2004 02:20:27 -0400 (EDT)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by psonek2@seznam.cz.
http://bugzilla.ximian.com/show_bug.cgi?id=61464
--- shadow/61464 2004-07-13 02:20:27.000000000 -0400
+++ shadow/61464.tmp.1671 2004-07-13 02:20:27.000000000 -0400
@@ -0,0 +1,91 @@
+Bug#: 61464
+Product: Mono: Class Libraries
+Version: unspecified
+OS: All
+OS Details: Gentoo linux
+Status: NEW
+Resolution:
+Severity:
+Priority: Cosmetic
+Component: Sys.XML
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: psonek2@seznam.cz
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: MS XmlSerializer can serialize ArrayList derived class with no public parameterless constructor, while Mono implementation cannot
+
+Hello,
+this code works under MS.NET, but throws following exception on mono beta3:
+
+Steps to reproduce the problem:
+
+
+using System;
+using System.IO;
+using System.Collections;
+using System.Xml.Serialization;
+
+namespace SerializationTest
+{
+[Serializable]
+public class MyList : ArrayList
+{
+Container container; // in real implementation i need to know "my container"
+
+// NOTE: MyList has no public constructor
+public MyList(Container container) : base() {
+this.container = container;
+}
+}
+
+[Serializable]
+public class Container
+{
+public MyList Items;
+
+public Container() {
+Items = new MyList(this);
+}
+
+public void Save(Stream s) {
+XmlSerializer serializer = new XmlSerializer(this.GetType());
+serializer.Serialize(s, this);
+}
+
+public static Container FromStream(Stream s) {
+XmlSerializer serializer = new XmlSerializer(typeof(Container));
+Container c = (Container) serializer.Deserialize(s);
+return c;
+}
+
+public static void Main()
+{
+Container c = new Container();
+c.Items.Add(1);
+using(FileStream fs = new FileStream("container.xml", FileMode.Create)) {
+c.Save(fs);
+}
+
+Container fromFile = Container.FromStream(File.OpenRead("container.xml"));
+Console.WriteLine("It works, first item is " + fromFile.Items[0]);
+Console.ReadLine();
+}
+}
+}
+
+Actual Results:
+System.InvalidOperationException: SerializationTest.MyList cannot be
+serialized because it does not have a default public constructor
+
+
+Expected Results:
+same as Actual Result, but it somehow works on MS .NET 1.1
+
+
+Additional Information: My opinion is that Mono works correctly here
+
+Exception under Mono seems logical to me. I am trying to serialize MyList
+class, that has no public constructor. But how is it possible to work under
+MS.NET? The reason must be, that MyList inherits from ArrayList.