https://bugzilla.novell.com/show_bug.cgi?id=685117
https://bugzilla.novell.com/show_bug.cgi?id=685117#c0 Summary: Binary deserialization of DataTable fails when a data table was added to an other object's SerializationInfo stream Classification: Mono Product: Mono: Class Libraries Version: unspecified Platform: i586 OS/Version: SLES 10 Status: NEW Severity: Normal Priority: P5 - None Component: CORLIB AssignedTo: [email protected] ReportedBy: [email protected] QAContact: [email protected] Found By: Community User Blocker: --- Description of Problem: Deserialization of DataTable - if the data table was added to an other object's SerializationInfo - are loosing the original data rows. In the below example the dataTable.Rows are null after deserialization. Steps to reproduce the problem: using System; using System.IO; using System.Data; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; class Test { static public void Main() { var f = new BinaryFormatter(); var m = new MemoryStream(); f.Serialize(m, GetData()); m.Position = 0; var c = f.Deserialize(m) as DataWrapper; Console.WriteLine(c.Name); return; } private static DataWrapper GetData() { DataTable dataTable = new DataTable(); dataTable.Columns.Add("name", typeof(string)); var dr = dataTable.NewRow(); dr["name"] = "anything"; dataTable.Rows.Add(dr); return new DataWrapper(dataTable.Rows[0]); } } [Serializable] public class DataWrapper : ISerializable { DataRow _dr; public DataWrapper(DataRow dr) { this._dr = dr; } protected DataWrapper(SerializationInfo info, StreamingContext context) { var table = (DataTable)info.GetValue("dt", typeof(DataTable)); _dr = table.Rows[0]; } public string Name { get { return _dr["name"].ToString(); } } public void GetObjectData(SerializationInfo info, StreamingContext context) { var dt = _dr.Table; info.AddValue("dt", dt); } } Actual Results: Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object at DataWrapper..ctor (System.Runtime.Serialization.SerializationInfo info, StreamingContext context) [0x00000] in <filename unknown>:0 at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod,object,object[],System.Exception&) at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00119] in /home/webdok/mono/mono-2.10.1/mcs/class/corlib/System.Reflection/MonoMethod.cs:526 --- End of inner exception stack trace --- at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0012c] in /home/webdok/mono/mono-2.10.1/mcs/class/corlib/System.Reflection/MonoMethod.cs:532 at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in /home/webdok/mono/mono-2.10.1/mcs/class/corlib/System.Reflection/MethodBase.cs:96 at System.Runtime.Serialization.ObjectRecord.LoadData (System.Runtime.Serialization.ObjectManager manager, ISurrogateSelector selector, StreamingContext context) [0x000fb] in /home/webdok/mono/mono-2.10.1/mcs/class/corlib/System.Runtime.Serialization/ObjectManager.cs:570 at System.Runtime.Serialization.ObjectManager.DoFixups () [0x00066] in /home/webdok/mono/mono-2.10.1/mcs/class/corlib/System.Runtime.Serialization/ObjectManager.cs:80 at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject (System.IO.BinaryReader reader) [0x0000f] in /home/webdok/mono/mono-2.10.1/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:145 at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph (BinaryElement elem, System.IO.BinaryReader reader, Boolean readHeaders, System.Object& result, System.Runtime.Remoting.Messaging.Header[]& headers) [0x00041] in /home/webdok/mono/mono-2.10.1/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/ObjectReader.cs:110 at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize (System.IO.Stream serializationStream, System.Runtime.Remoting.Messaging.HeaderHandler handler) [0x0007a] in /home/webdok/mono/mono-2.10.1/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:163 at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize (System.IO.Stream serializationStream) [0x00000] in /home/webdok/mono/mono-2.10.1/mcs/class/corlib/System.Runtime.Serialization.Formatters.Binary/BinaryFormatter.cs:120 at Test.Main () [0x00000] in <filename unknown>:0 Expected Results: the "anything" string on the console. How often does this happen? Always. Additional Information: Serialization seems to be ok, I've tried to serialize under Mono and deserialize under ms.net - works fine. You can workaround this by serializing DataTable to the memory stream and add that stream to the SerializationInfo object of actually serialized parent-object. -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the QA contact for the bug. You are the assignee for the bug. _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
