binary serialization, adding a new field to class - will it work?

后端 未结 2 393
你的背包
你的背包 2021-01-14 00:08

I have a client and a server application which communicate over .NET 2.0 Remoting using binary serialization.

A small change has been made to one of the data transfe

2条回答
  •  终归单人心
    2021-01-14 00:29

    You can add an attribute to the new property: OptionalField. Without the attribute, the deserializer will not be able to convert serialized data back to the updated definition. The attribute is to ensure the deserializer can handle the "missing" data gracefully.

    If you want to set a default value for the new property, in the case that no appropriate data for it is deserialized, implement the IDeserializationCallback interface, and set the default value, if any, in the resulting method.

提交回复
热议问题