c# - How much does a class/object have to change in order for binary-deserialization to fail -


we have solution storing large/complex c# object in our database binary data. concern when changes made class, run risk data saved database fail on deserialization after code change.

here code we're using serialize objects:

    public static byte[] serializeobject(object tobeserialized)     {         var stream = new memorystream();         var serializer = new binaryformatter();         serializer.serialize(stream, tobeserialized);         stream.position = 0;         return stream.toarray();     } 

here our deserialize method:

    public static t deserializeobject<t>(byte[] tobedeserialized)     {         using (var input = new memorystream(tobedeserialized))         {             var formatter = new binaryformatter();             input.seek(0, seekorigin.begin);             return (t) formatter.deserialize(input);         }     } 

my question is, has change/how has change in order deserialization of older object fail?

always make serialization version tolerance, in this article can find advice how it

also can find cases, break serialization/deserialization below

  • when remove serialized field

  • when apply nonserializedattribute attribute field if attribute not applied field in previous version.

  • when change name or type of serialized field.

  • when adding new serialized field, without optionalfieldattribute attribute.

  • when removing nonserializedattribute attribute field (that not serializable in previous version), without optionalfieldattribute attribute.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -