BinaryFormatter produce larger file after ISerializable implemente

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Question about serialization to binary format under .Net 1.1 using C#.

I have some set of classes, some of them are marked with
SerializableAttribute. I use serialization to binary files to persist some
object graph between app sessions.

I've made an easy change to my code: each class which is marked as
Serializable implements ISerializable i-face now, and contains
deserialization ctor. The GetObjectData method is implemented very easy: each
field that was serialized automatically is added to SerializationInfo now by
call to AddValue.

Now, what is my problem. If I serialize an object graph to file by
BinaryFormatter using new classes version (ISerializable) I got a larger file
(about 2 times) that before.

Why??
 
It looks like the problem is because of serialization of descendants of
abstract classes, but I'm not sure.

Any ideas?
 
Woohoo!! Someone else noticed my favorite problem!

See this thread:
http://groups.google.com/group/micr...*dotnet*+author:Hooker&hl=en#c94132480ff4eeb2

For a detailed - and sometimes painful - history.

The short answer to your question (and it isn't really an answer) was given
at the end of the chain:

****************
AFAIK, the builtin serialization will optimize for better performance under
certain circumstances. While for custom serialization, it has to strictly
follow the ISerializable.GetObjectData() you provided to repeat an extra
100 times of "SerializationTest.ChildNodeval1parentsubNode" as in this
case.
****************

Cheers,
Rob
 
Back
Top