We have a solution in which we store a rather large / complex C # object in our database as binary data. I am worried that when changes are made to this class, we risk that the data stored in the database will fail to deserialize after changing the code.
Here is the code we use to 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 is 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 what needs to be changed / how much needs to be changed so that deserialization of the older object is unsuccessful?
Ben source
share