Bug 313926 (MONO54614) - Compatiblity problems between platforms with BinaryFormatter
Summary: Compatiblity problems between platforms with BinaryFormatter
Status: RESOLVED MOVED
Alias: MONO54614
Product: Mono: Runtime
Classification: Mono
Component: misc (show other bugs)
Version: unspecified
Hardware: Other Other
: P3 - Medium : Enhancement
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-02-19 22:05 UTC by Giles Forster
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 18:28:00 UTC


---- Reported by gileslforster@yahoo.co.uk 2004-02-19 15:05:50 MST ----

Description of Problem:

Using Mono 0.30 and .NET 1.1 on Windows, Serialisation of some simple 
objects produce incompatable results. 

On Windows, serialization of the objects bellow, and desrialization 
works. 

On Mono, Serialization of the objects below, and deserialization work.

Serialization on Windows and Deserialization on Mono works

Serialization on Mono and Deserialization on Mono DOES NOT.

To summarise.

Windows to Windows - Ok
Mono to Mono - Ok
Windows to Mono - Ok
Mono to Windows - Fails


Steps to reproduce the problem:
1. Using the folling classes

using System;
using System.IO;
using System.Collections;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;
using System.Runtime.Serialization.Formatters.Binary;

[Serializable()]
	public class SimpleObject : IDeserializationCallback
	{
		private string name;
		private int id;

		[NonSerialized()]
		public static int Count;

		public string Name
		{
			get { return name; }
			set { name = value; }
		}

		public int ID
		{
			get { return id; }
			set { id = value; }
		}

		static SimpleObject()
		{
			Count = 0;
		}

		public SimpleObject()
		{
			name = "bob";
			id = 10;
			Count++;
		}

		public SimpleObject(string name, int id)
		{
			this.name = "bob";
			this.id = 10;
			Count++;
		}

		~SimpleObject()
		{
			Count--;
		}

		void IDeserializationCallback.OnDeserialization(Object 
sender) 
		{
			Count++;
		}
	}

	[Serializable()]
	public class NotSoSimpleObject : SimpleObject
	{
		private string thingy;

		public NotSoSimpleObject()
		{
			thingy = "Hello";
		}

		public NotSoSimpleObject(string name, int id) 
			: base(name, id)
		{
			thingy = "Hello";
		}
	}

	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			int i;
			BinaryFormatter bf = new BinaryFormatter();
			SimpleObject simple = null;

			//========================
			// Serialisation Test
			//========================

			ArrayList vec = new ArrayList();
			
			simple = new NotSoSimpleObject("Testing Object", 
1);

			Stream sw = File.Create("SimpleObjects.bin");

			bf.Serialize(sw, simple);
			sw.Close();

			Console.WriteLine("Created Simple object.");

			//========================
			// Deserialization Test
			//========================
			Stream sr = File.OpenRead("SimpleObjects.bin");
			simple = (SimpleObject)bf.Deserialize(sr);

			Console.WriteLine("Loaded Simple Object");

			sr.Close();
		}
	}


2. 

In the main function, comment out the Serialize and Deserialize 
respectively on Mono and Windows to test, serialising in and out of the 
different systems. The both create a file called simple.bin
3. 

Actual Results:

Fails loading on .NET 1.1 when writing from Mono

Expected Results:

Should work.

How often does this happen? 

Always, never mind what happens when you try to use something like an 
ArrayList, as all the Systrem defined objects seem completely 
incompatible.

Additional Information:

Looking at what is produced in each, Mono seems to not add the full 
qualifiers of member fields to the object it belongs to. e.g Mono 
writes "name" instead of "SimpleObject+Name" - could this be causing the 
problem.

Anyway, I suspect many people are using serialization to save and load 
data easily, and they are going to find this a real problem in the 
future, if they can't even read and write their own types in a consistent 
manner, never mind as I said things like the ArrayList.



---- Additional Comments From lluis@ximian.com 2004-02-23 09:01:20 MST ----



*** This bug has been marked as a duplicate of https://bugzilla.novell.com/show_bug.cgi?id=MONO54439 ***


Unknown bug field "cf_op_sys_details" encountered while moving bug
   <cf_op_sys_details>XP and Mandrake 9.2</cf_op_sys_details>
Unknown operating system unknown. Setting to default OS "Other".
This bug was marked DUPLICATE in the database it was moved from.
    Changing resolution to "MOVED"