Simple data file versioning with DataContractSerializer

后端 未结 2 1813
不知归路
不知归路 2021-01-05 08:37

Having read Data Contract Versioning we concluded that it\'s not really the whole story. For example, what happens if you used to have ValueA, and in the new version it\'s n

相关标签:
2条回答
  • 2021-01-05 09:04

    1 year later I have to say that DataContractSerializer has really sucked for versioning. It's far too rigid. It's really meant for contracts that aren't very likely to change, and then only in specific ways. You have to do extra work to use it just to make it fast - like the KnownTypeAttribute for example. I would only recommend it if you require relatively fast serialization - which, arguably, is rather important for what it was designed for.

    Another project I work on uses a more flexible serializer which, for example, doesn't skip calling the class constructor (something has has caused much inconvenience), and doesn't require items to be in a specific order. It deals gracefully with new fields (they are left at whatever the constructor set them to) and removed fields with zero programmer intervention.

    Now if only I could post it here... It is however about 5x-10x slower than the DataContractSerializer.

    0 讨论(0)
  • 2021-01-05 09:08

    I think you're expecting too much from the built-in versioning support. It's really intended to allow you to add new members while retaining all existing functionality and therefore members.

    In the case of breaking changes to a contract, you'd probably be better creating a new version of the contract (e.g. using a new namespace - a common convention is to use a suffix yyyy/mm, e.g. http://mycompany.com/myservices/2009/10).

    You then need to be able to support as many old contracts as is appropriate, and need to be able to convert between each supported contract and whatever current internal representation you are using.

    0 讨论(0)
提交回复
热议问题