- Home /
Binary serialization layout on different platforms
Hi, I use binary serialization with [Serializable] decorators to create a snapshot of my game world state. Then to compare equality of different world states I count a hash from the byte array created by BinaryFormatter.
On different platforms, namely iOS and Android, the serializer produces different byte layouts for the same game state. Both are valid and deserialize to the same state. However, as the layout differs, I get different hashes for the same state on different platforms. Why do the layouts differ? Does reflection go through object fields in different order on different platforms?
As a quick fix I implemented a light old-school binary serialization with interfaces and hand-tunable serialization order, but in the long run it is not as easily maintainable as automatic serialization.