[Mono-bugs] [Bug 75735][Wis] New - [GMCS] problems with generic struct deserialization

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sat Aug 6 17:23:15 EDT 2005


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 malekith at pld-linux.org.

http://bugzilla.ximian.com/show_bug.cgi?id=75735

--- shadow/75735	2005-08-06 17:23:15.000000000 -0400
+++ shadow/75735.tmp.6910	2005-08-06 17:23:15.000000000 -0400
@@ -0,0 +1,102 @@
+Bug#: 75735
+Product: Mono: Runtime
+Version: 1.1
+OS: 
+OS Details: amd64 pld linux
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: malekith at pld-linux.org               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: [GMCS] problems with generic struct deserialization
+
+Description of Problem:
+
+The following example either asserts at runtime or throws null reference
+exception:
+
+
+using System;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters.Binary;
+
+[Serializable]
+public struct Tuple <a,b> {
+  public a field1;
+  public b field2;
+
+  public Tuple (a x, b y) {
+    field1 = x;
+    field2 = y;
+  }
+}
+
+
+public class Test {
+   public static void Main()  {
+
+      //Creates a new TestSimpleObject object.
+      TestSimpleObject obj = new TestSimpleObject();
+
+      Console.WriteLine("Before serialization the object contains: ");
+      obj.Print();
+
+      //Opens a file and serializes the object into it in binary format.
+      Stream stream = File.Open("data.xml", FileMode.Create);
+      BinaryFormatter formatter = new BinaryFormatter();
+
+      //BinaryFormatter formatter = new BinaryFormatter();
+
+      formatter.Serialize(stream, obj);
+      stream.Close();
+
+      //Empties obj.
+      obj = null;
+
+      //Opens file "data.xml" and deserializes the object from it.
+      stream = File.Open("data.xml", FileMode.Open);
+      formatter = new BinaryFormatter();
+
+      //formatter = new BinaryFormatter();
+
+      obj = (TestSimpleObject)formatter.Deserialize(stream);
+      stream.Close();
+
+      Console.WriteLine("");
+      Console.WriteLine("After deserialization the object contains: ");
+      obj.Print();
+   }
+}
+
+
+// A test object that needs to be serialized.
+[Serializable()]
+public class TestSimpleObject  {
+
+    public Tuple <string,int>  member6;
+
+    public TestSimpleObject() {
+        member6 = new Tuple <string, int> ("aa", 22);
+    }
+
+
+    public void Print() {
+        Console.WriteLine("member6 = '{0} {1}'", member6.field1,
+member6.field2);
+    }
+}
+
+With the attached patch it runs, but doesn't deserialize the object correctly.
+
+It works OK with class instead of struct (like in #75299).
+
+Additional Information:
+
+I'm running mono svn trunk.


More information about the mono-bugs mailing list