Home All Groups Group Topic Archive Search About

OptionalFieldAttribute Experiments in .NET 2.0

Author
22 Dec 2005 4:58 PM
Raghu
It has been written in numerous web logs about the OptionalFieldAttribute
and that it should be used as version tolerance mechansim in .net framework
2.0. However I found that even without using this attribute, .net framework
does not fail when a new member is introduced (without the
OptionalFieldAttribute) into the type while deserializing the stream written
with previous version.

This surprised me. So I serialized a type with 2 members into a file using
BinaryFormatter. Later I introduced another member but removed one of the
existing members from the same type and deserialized instance from the file.
Note that I have not used OptionalFieldAttribute at all. Even this
experiment succeeded without any problem. The new member is initialized to
the default value. Also I have not used any of the new OnDeserializing,
OnDeserialization, OnSerializing or OnSerialization attributes.

I also tried changing the assembly version when a new member is introduced.
This did not affect the results.

Does any one have any explanation?

Thanks.
Raghu/..

AddThis Social Bookmark Button