NetDataContractSerializer 和程序集版本不匹配
我正在使用 NetDataContractSerializer 在应用程序之间交换数据。我希望 ReadObject 方法在程序集版本不匹配时抛出异常。
现在,例如,当我从程序集版本 1.0.0.0 序列化我的对象,然后将其反序列化为具有相同程序集但现在版本 1.0.0.1 时,NetDataContractSerializer 愉快地吞下流并且反序列化没有问题。
当版本不匹配时是否可以中止反序列化过程?
更新:由于多种原因,我需要版本不容忍。这既是客户的要求,也是绝对确定导入处理从同一版本的应用程序导出的文件的要求。就我的应用程序而言,更改版本会使之前的导入过程变得无用,因为版本更改或多或少涉及内部结构更改。
I'm using NetDataContractSerializer to exchange data among applications. I would like the ReadObject method throw an exception when assembly versions don't match.
Now, for example, when I serialized my object from assembly version 1.0.0.0 and later deserialize it having same assembly but now version 1.0.0.1, the NetDataContractSerializer happily swallows the stream and deserializes without problems.
Is it possible to abort the deserialization process when versions don't match?
UPDATE: I need version intolerance because of many reasons. This is both a requirement from a customer, as well as a requirement to be absolutely certain that import processes the file that was exported from the same version of the application. In case of my application, changing version makes useless the previous import process, because version change equals to more or less involved internal structure change.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
丑陋但有效(最好是在你的根对象上):
Ugly but effective (ideally on your root object):