Z
Z
zbender2014-10-29 23:12:54
C++ / C#
zbender, 2014-10-29 23:12:54

How to deserialize a modified object?

Serialized the class instance to a file:

Stream FileStream = File.Create(filePath);
BinaryFormatter serializer = new BinaryFormatter();
serializer.Serialize(FileStream, Object);

After the class has been changed. Added and removed fields.
When deserializing:
Stream FileStream = File.OpenRead(filePath);
BinaryFormatter deserializer = new BinaryFormatter();
object Object = deserializer.Deserialize(FileStream);

an exception occurs:
The ObjectManager encountered an invalid number of address bindings. This usually indicates errors in the Formatter.

It is necessary to get data from one field of the saved object. This field, when editing the class, remained untouched. Version control was not used, so it will not be possible to return the class to the state in which the serialization took place.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aush, 2014-10-30
@aush

Do you want to solve the general problem of deserializing a changed type, or do you need to get data from one specific file? If 1, then drop this case, if 2, then you can just look at the serialized data:
772a7beefb1e4dd6925f631cb1396654.pngbd0f0b69aa4b47b3a3667b15f4f441f8.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question