Deserialization version mismatch

G

Guest

I have a class which is serialized and stored in a file stream. Later I
changed the class with adding some fields to it. Now when I deserialize (I
am deserializing from a later version of my Application) the file framework
throws an exception stating that “Possible Version mismatch. Type [whatever]
has x members, number of members deserialized is y.". Kindly let me know any
work arounds for this problem. If possible send me a sample code that solves
this problem.
 
N

Nicholas Paldino [.NET/C# MVP]

Rohith,

The only way around this problem is to use custom serialization. This
way, you can pull the values from the serialization info passed to your
constructor.

If you are using .NET 2.0, you can use the OptionalField attribute on a
field to indicate that it is optional to be populated. Of course, once you
do this, you would have to make sure that all new fields added to your type
are optional, or non serializable.

Hope this helps.
 
G

Guest

Thanks Nicholas...It helps

Nicholas Paldino said:
Rohith,

The only way around this problem is to use custom serialization. This
way, you can pull the values from the serialization info passed to your
constructor.

If you are using .NET 2.0, you can use the OptionalField attribute on a
field to indicate that it is optional to be populated. Of course, once you
do this, you would have to make sure that all new fields added to your type
are optional, or non serializable.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rohith said:
I have a class which is serialized and stored in a file stream. Later I
changed the class with adding some fields to it. Now when I deserialize
(I
am deserializing from a later version of my Application) the file
framework
throws an exception stating that "Possible Version mismatch. Type
[whatever]
has x members, number of members deserialized is y.". Kindly let me know
any
work arounds for this problem. If possible send me a sample code that
solves
this problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top