Check whether binary serialized data matches the class which serialized it

邮差的信 提交于 2019-12-11 22:22:07

问题


The title says pretty much what I would like to know. I have data which was binary serialized and now I'm reading it again (class name remains the same) and I would like to know if the serializer misses something because, for example, a private backing field might have been renamed.

I did the following refactoring:

private string descriptionField;
public string Description
{
  get { return this.descriptionField; }
}

to

public string Description { get; private set; }

As stated in in this article this won't work. But I really would like to know if there is a way to detect if the class does not match the serialized data.

I do not want to do the serialization myself via implementing ISerializable because the class and its properties is quite large and might be changed. I'd prefer a easier solution =)


回答1:


But I really would like to know if there is a way to detect if the class does not match the serialized data?

One way to detect it would be to serialize the existing class with the same data as in the previous serialized file and then compare the digital fingerprints of the previous and current serialized files.

I do not want to do the serialization myself via implementing ISerializable because the class and its properties is quite large and might be changed.

Since you are using the BinaryFormatter and dealing with potentially significant versioning issues, i think your only option is to implement ISerializable and handle deserialization yourself whether you like it or not.



来源:https://stackoverflow.com/questions/26510721/check-whether-binary-serialized-data-matches-the-class-which-serialized-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!