Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Version compatibility with .NET serialization?

What are the methods of implementing version compatibility with .NET serialization?

like image 847
Gayan Dhanushka Avatar asked Nov 14 '22 02:11

Gayan Dhanushka


1 Answers

If you mean with BinaryFormatter (which is usually where this kicks) - don't; it isn't (IMO) suitable for storage - only for transport (and versioning is much less an issue here, as you probably control both ends of the pipe). Many other serializers of every variety are available; most of them cope just fine with versioning.

Personally, I would go for:

  • xml: XmlSerializer (DataContractSerializer isn't as flexible in the output, but can handle graphs)
  • json: JavaScriptSerializer
  • binary: protobuf-net (I'm biased here)

With any of these, you should be fine between versions, adding members, renaming fields, etc.

Actually, I'd use the above 3 even if I was just transporting (not storing).

like image 100
Marc Gravell Avatar answered Jan 02 '23 10:01

Marc Gravell