473,513 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.NET 2.0 (RTM) serialization does not thror exception for missing/changed properties!

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.

Nov 17 '05 #1
3 1140
> 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?


This is an improvment!
Strict serialization was causing way more problem than it solved.

Anyway if you like an exception to be thrown, .. uh....
I don't know.... there is no obvious way but I think there is a way, I just
can't remember it now..
Nov 17 '05 #2
Do you know any URL that mentions this change?

Nov 17 '05 #3
uh....
I read about it (and also people complaining about that) a long while ago.
mostly when I was interested in Remoting and many remoting users complained
that this exact version matching was real pain for them.

Now, I can't remember where, but maybe you could google for something as
"Serialization C# Remoting missing field 2.0" ?

"Tuncay Baskan" <tb*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Do you know any URL that mentions this change?

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1594
by: HakonB | last post by:
Hi all I get an exception when trying to deserialize a simple configuration file using XML Serialization. The very long stacktrace can be seen at the bottom of this message. I've see other...
4
2308
by: ron | last post by:
Hi, I have class object that i serialize using the System.Xml.Serialization class. Intermittently the object is not getting serialized correctly, using System.Xml.Serialization classes....
4
7804
by: Andreas Huber | last post by:
Hello there I need to serialize/deserialize some pretty simple data structures (no inheritance, few has relationships, ~20 classes) in three formats. One is XML (structure is not important as...
5
2356
by: Arjen | last post by:
Hello, Can somebody help me a little bit? I can't get it to work. Please see my code below... I have placed some comments like "// And whats next?". I'm sure that I have to code something...
5
2812
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
0
1239
by: Goethals Frederik | last post by:
Hi, I have some questions that are a little difficult to explain, so I give it a try... I have an application (aSP.NET with VB.NET codebehind) and I would like to store my data on disk...
6
6044
by: John Glover | last post by:
I'm having a very strange problem with XML serialization. I'm writing web services which pass instances of various classes back and forth as parameters and return values of web methods. The...
0
422
by: Craig Vermeer | last post by:
Hi all, I'm hoping that someone has seen this before. I wasn't able to find any solutions through my usual channels (I.E Google). I'm getting the following exception in certain situations...
5
4311
by: RobinS | last post by:
I want to serialize a class that I am using to retain some information the user types into a screen. I have 3 questions. 1) I serialized it as XML to start with. This works, but how do I...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.