[Mono-devel-list] Different behaviour deserializing ISerializable trees Mono <-> .NET
Jörg Rosenkranz
joergr at voelcker.com
Mon Aug 25 09:29:11 EDT 2003
Hi all,
I have run into a problem serializing/deserializing classes which
implement ISerializable.
I have two classes:
1) A data holding class.
2) A collection class for objects of class 1
Both classes implement ISerializable. The class 1 objects are
stored in class 2 in a Hashtable internally. I want to restore key
to object relation in the deserialization constructor of the
collection class.
My problem is that the collection elements are deserialized *after* the
collection class. When I access them in the constructor of class 2
they are empty.
You can try the attached sample. It doesn't use Hashtable but shows
the different behaviour. Using Mono it prints:
========== Serialization ==========
Serializing TestCollection...
0 - Adding member: Value1=member1, Value2=test1 ...
1 - Adding member: Value1=member2, Value2=test2 ...
2 - Adding member: Value1=member3, Value2=test3 ...
TestCollection serialized.
Serializing TestMember: Value1=member3, Value2=test3 ...
TestMember serialized.
Serializing TestMember: Value1=member1, Value2=test1 ...
TestMember serialized.
Serializing TestMember: Value1=member2, Value2=test2 ...
TestMember serialized.
========== Deserialization ==========
Deserializing TestCollection...
0 - New deserialized member: Value1=, Value2= ...
1 - New deserialized member: Value1=, Value2= ...
2 - New deserialized member: Value1=, Value2= ...
Deserialized TestCollection.
Deserializing TestMember...
Deserialized TestMember: Value1=member3, Value2=test3
Deserializing TestMember...
Deserialized TestMember: Value1=member1, Value2=test1
Deserializing TestMember...
Deserialized TestMember: Value1=member2, Value2=test2
========== Result ==========
0: Value1=member1, Value2=test1
1: Value1=member2, Value2=test2
2: Value1=member3, Value2=test3
Running (and compiled too!!) under MS .NET:
========== Serialization ==========
Serializing TestCollection...
0 - Adding member: Value1=member1, Value2=test1 ...
1 - Adding member: Value1=member2, Value2=test2 ...
2 - Adding member: Value1=member3, Value2=test3 ...
TestCollection serialized.
Serializing TestMember: Value1=member1, Value2=test1 ...
TestMember serialized.
Serializing TestMember: Value1=member2, Value2=test2 ...
TestMember serialized.
Serializing TestMember: Value1=member3, Value2=test3 ...
TestMember serialized.
========== Deserialization ==========
Deserializing TestMember...
Deserialized TestMember: Value1=member1, Value2=test1
Deserializing TestMember...
Deserialized TestMember: Value1=member2, Value2=test2
Deserializing TestMember...
Deserialized TestMember: Value1=member3, Value2=test3
Deserializing TestCollection...
0 - New deserialized member: Value1=member1, Value2=test1 ...
1 - New deserialized member: Value1=member2, Value2=test2 ...
2 - New deserialized member: Value1=member3, Value2=test3 ...
Deserialized TestCollection.
========== Result ==========
0: Value1=member1, Value2=test1
1: Value1=member2, Value2=test2
2: Value1=member3, Value2=test3
As you can see the result is the same after deserialization
but not inside the constructor.
Is this a bug or a feature or simply bad usage of serialization? ;-)
And no, I can't serialize the Hashtable directly because then it
would be binary imcompatible between Mono and .NET.
Thanks in advance for any comments,
Jörg
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ClassSerialization.cs
Type: application/octet-stream
Size: 3750 bytes
Desc: ClassSerialization.cs
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20030825/6e46256c/attachment.obj
More information about the Mono-devel-list
mailing list