二进制序列化,增加一个新的领域,以一流的 - 将它的工作? [英] binary serialization, adding a new field to class - will it work?

查看:143
本文介绍了二进制序列化,增加一个新的领域,以一流的 - 将它的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个客户端和服务器应用程序,它进行通信.NET 2.0使用二进制序列化远程处理。

I have a client and a server application which communicate over .NET 2.0 Remoting using binary serialization.

一个小的变化已对数据传输对象的接口,并实现类,好了,弦场数组加入。

A small change has been made to one of the data transfer object's interface and the implementing class, well, an array of strings field was added.

如果我重新部署的服务器应用程序的新版本,将我的老客户继续工作?

If I to redeploy a new version of server application, will my old clients continue to work?

我会认为他们会的,因为没有已被删除从接口直接实现,但我不知道。

I would think they would, since nothing has been deleted from interface and direct implementation, but I am not sure.

这也许可以归结为一个问题 - 是一个二元解串器不够聪明来 通过初始化一个领域没有找到数据输入二进制流为null处理这样的情况下,还是要打破,并抛出异常?

It probably boils down to another question - is a binary deserialiser "clever enough" to handle the situation like this by initializing a fields it fails to find data in the input binary stream to null, or is it going to break and to throw the exception?

推荐答案

您可以添加属性的新属性: OptionalField 。无属性,解串行器将无法以序列化的数据转换回更新的定义。属性是为了确保解串器可以处理丢失的数据正常。

You can add an attribute to the new property: OptionalField. Without the attribute, the deserializer will not be able to convert serialized data back to the updated definition. The attribute is to ensure the deserializer can handle the "missing" data gracefully.

如果你想设置的默认值的新属性,因为它没有适当的数据进行反序列化的情况下,实施 IDeserializationCallback 接口,并设置默认值,如果有的话,在生成的方法

If you want to set a default value for the new property, in the case that no appropriate data for it is deserialized, implement the IDeserializationCallback interface, and set the default value, if any, in the resulting method.

这篇关于二进制序列化,增加一个新的领域,以一流的 - 将它的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆