T
Tuncay Baskan
Hi all,
Serialization behavior of .NET 2.0 (RTM version) is very strange. I
have the following simple code:
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
[Serializable]
public class SampleClass {
public SampleClass(string name) {
this.m_Name = name;
}
private string m_Name = "";
public string Name {
get { return m_Name; }
set { m_Name = value; }
}
}
class Program {
static void Main(string[] args) {
Read();
}
static void Write() {
Stream str = File.Create("c:\\deneme1.bin");
BinaryFormatter frm = new BinaryFormatter();
frm.Serialize(str, new SampleClass("A String"));
str.Close();
}
static void Read() {
Stream str = File.OpenRead("c:\\deneme1.bin");
BinaryFormatter frm = new BinaryFormatter();
object l=frm.Deserialize(str);
str.Close();
}
}
Later I change the name of the private field 'm_Name' to 'm_Name1' and
even property name to 'Name1' too. And in Main method call the Read()
method.
I get no exception! No error message, no warning, nothing!
When I debug the Read() method after deserializing I see that class
constructed . I tried the exact same code on Visual Studio 2003 with
..NET 1.1 and it throws serialization exception correctly.
This seems very very weird to me. We tried the same code on different
machines in the LAN and I believe it has nothing to do with
installation issues.
Can anyone enlighten me what is going on?
Thanks.
/tb.
Serialization behavior of .NET 2.0 (RTM version) is very strange. I
have the following simple code:
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
[Serializable]
public class SampleClass {
public SampleClass(string name) {
this.m_Name = name;
}
private string m_Name = "";
public string Name {
get { return m_Name; }
set { m_Name = value; }
}
}
class Program {
static void Main(string[] args) {
Read();
}
static void Write() {
Stream str = File.Create("c:\\deneme1.bin");
BinaryFormatter frm = new BinaryFormatter();
frm.Serialize(str, new SampleClass("A String"));
str.Close();
}
static void Read() {
Stream str = File.OpenRead("c:\\deneme1.bin");
BinaryFormatter frm = new BinaryFormatter();
object l=frm.Deserialize(str);
str.Close();
}
}
Later I change the name of the private field 'm_Name' to 'm_Name1' and
even property name to 'Name1' too. And in Main method call the Read()
method.
I get no exception! No error message, no warning, nothing!
When I debug the Read() method after deserializing I see that class
constructed . I tried the exact same code on Visual Studio 2003 with
..NET 1.1 and it throws serialization exception correctly.
This seems very very weird to me. We tried the same code on different
machines in the LAN and I believe it has nothing to do with
installation issues.
Can anyone enlighten me what is going on?
Thanks.
/tb.