[Mono-bugs] [Bug 74737][Nor] New - Formatters.Binary differences in serialization of a float on MS.NET and MONO
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Tue, 26 Apr 2005 12:25:53 -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 davide.morelli@parser.it.
http://bugzilla.ximian.com/show_bug.cgi?id=74737
--- shadow/74737 2005-04-26 12:25:53.000000000 -0400
+++ shadow/74737.tmp.12111 2005-04-26 12:25:53.000000000 -0400
@@ -0,0 +1,154 @@
+Bug#: 74737
+Product: Mono: Runtime
+Version: 1.1
+OS: Mac OS X 10.3
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: io-layer
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: davide.morelli@parser.it
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Formatters.Binary differences in serialization of a float on MS.NET and MONO
+
+Description of Problem:
+
+a float serialized on Mono with Formatters.Binary will not be correctly
+deserialized on MS.NET and vice versa
+
+Steps to reproduce the problem:
+
+1. write this file:
+
+----------------------file testBugBinary.cs
+
+using System;
+using System.IO;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters;
+using System.Runtime.Serialization.Formatters.Binary;
+
+
+namespace testSerializza1
+{
+ public class HelloWorld
+ {
+ public static void Main(string[] args)
+ {
+ if (args[0]=="save")
+ salvalo("test" + args[1]);
+ if (args[0]=="load")
+ caricalo("test" + args[1]);
+ }
+
+ public static void salvalo(string filename)
+ {
+ Stream myStream = null;
+ myStream = new FileStream(filename,
+FileMode.Create);
+ if (myStream != null)
+ {
+ //SoapFormatter formatter = new
+SoapFormatter();
+ BinaryFormatter formatter = new
+BinaryFormatter();
+ formatter.AssemblyFormat =
+FormatterAssemblyStyle.Simple;
+ float test = 10f;
+ //Documento doc = new Documento(10,10);
+ formatter.Serialize(myStream, test);
+ Console.WriteLine("float = " +
+test.ToString());
+ myStream.Close();
+ }
+ }
+
+ public static void caricalo(string file)
+ {
+ string filename = "";
+ Stream myStream = null;
+
+ try
+ {
+ filename = file;
+ myStream = File.Open(file, FileMode.Open,
+FileAccess.Read, FileShare.None);
+ }
+ catch (Exception ex)
+ {
+ myStream.Close();
+ Console.WriteLine("erroreOpen: " +
+ex.Message);
+ }
+ try
+ {
+
+ if (myStream != null)
+ {
+ Console.WriteLine("ho letto dal
+file: " + filename);
+
+
+ BinaryFormatter formatter = new
+BinaryFormatter();
+
+ formatter.AssemblyFormat =
+FormatterAssemblyStyle.Simple;
+
+
+ float test = (float)
+formatter.Deserialize(myStream);
+ Console.WriteLine("flaot = " +
+test.ToString());
+
+ myStream.Close();
+
+ }
+ }
+ catch (Exception ex)
+ {
+ myStream.Close();
+ Console.WriteLine("error: " + ex.ToString
+());
+ }
+ }
+ }
+}
+
+----------------------end of file testBugBinary.cs
+
+2. compile this code in MS.NET
+csc testBugBinary.cs
+
+3. Compile it also on OS X
+mcs testBugBinary.cs
+
+4. now serialize a float on MS.NET and on Mono (OSX)
+on windows run the program with these args:
+testBugBinary save MS
+
+5.on MAC OS X run the program with these args:
+testBugBinary save MONO
+
+6.now copy "testMONO" (a serialized float wrote by MONO) on Win
+and copy "testMS" (a serialized float wrote by MS) on OSX
+
+7. now deserialize to see the wrong behaviour
+on win with
+testBugBinary load MONO
+
+and on OSX with
+mono testBugBinary load MS
+
+Results:
+a float serialized as 10f is deserialized as 1,157052e-41 when
+serializing on MS.NET and deserializing on MONO and vice-versa
+
+
+How often does this happen?
+always