BinaryFormatter ignore assembly version

天涯浪子 提交于 2019-12-01 06:43:17

But when I change the version of the assembly, the hash is changing even when the object is the same.

yes, that is expected behaviour when using BinaryFormatter... it does not guarantee to create the same output - and especially since it includes full type information (including version) it is pretty much guaranteed to change between versions.

I would consider using a serializer that doesn't include type information; XmlSerializer, Json.NET or protobuf-net would leap to mind.

BinaryFormatter.AssemblyFormat is documented as:

Gets or sets the behavior of the deserializer with regards to finding and loading assemblies.

There's no indication that it has an impact on the serializing path.

Personally I would avoid this method of hashing - it seems terribly fragile to me. Do you have no control over the object being hashed, or any way of hashing in a more stable way?

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