I have data stored in an instance of a class that has been serialized with .net BinaryFormatter. Now I want to rename one of the fields in the class, but still be able to deserialize the old data.
One option is to implement ISerializable and deserialize all the fields of the class manually. But this seems like a lot of work, especially if my class has many fields, and I just renamed one field.
Is there a better way?
Craig suggests saving a copy of the old class for deserialization and copying the values into the new class. I also saw this elsewhere - what advantage does this have for implementing ISerializable? As far as I see, copying the class leaves me with 2 almost identical copies of the class, plus I still have to copy all the values from the old class to the new class, which seems to be the same amount of work as implementing ISerializable using an almost duplicated class thrown into mix
Two answers mention Binders. I successfully used the SerializationBinder to deserialize the Bar class, which was serialized as the Foo class, but this is because the class name has changed. Does SerializationBinder help when you rename a field - say, when int m_Left was renamed to int m_Right?
c # serialization
Tim gradwell
source share