Bugzilla – Bug 318674
[GMCS] problems with generic struct deserialization
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by malekith@pld-linux.org 2005-08-06 17:23:15 MST ---- 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. ---- Additional Comments From malekith@pld-linux.org 2005-08-06 17:24:23 MST ---- Created an attachment (id=168319) partial fix ---- Additional Comments From miguel@ximian.com 2005-08-23 13:36:33 MST ---- martin, can you review/approve? ---- Additional Comments From malekith@pld-linux.org 2005-08-23 13:38:25 MST ---- Remark: the patch doesn't solve the problem, just part of it. ---- Additional Comments From martin@ximian.com 2005-09-05 03:08:37 MST ---- Fixed. ---- Additional Comments From martin@ximian.com 2005-09-05 03:09:17 MST ---- I mean, I applied the patch. ---- Additional Comments From miguel@ximian.com 2005-09-25 16:53:14 MST ---- Lluis, we need some help here, can you look at this bug? ---- Additional Comments From lluis@ximian.com 2005-09-26 07:41:15 MST ---- It fails because reflection has problems with generic struct values. This problem is reported in https://bugzilla.novell.com/show_bug.cgi?id=MONO76136. ---- Additional Comments From vargaz@gmail.com 2005-11-15 14:09:09 MST ---- This one is fixed as well. This bug depended on bug(s) 76136. Imported an attachment (id=168319) Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>amd64 pld linux</cf_op_sys_details> Unknown operating system unknown. Setting to default OS "Other".