具有不同程序集版本的二进制反序列化 [英] Binary Deserialization with different assembly version

查看:136
本文介绍了具有不同程序集版本的二进制反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用BinaryFormatter序列化带有字符串和布尔值的结构的项目?

I have a project which uses BinaryFormatter to serialize a collection of structs with string and bool? datatypes.

序列化/反序列化工作正常,但是,如果我要更改执行该工作的程序集,则由于二进制文件中的标头指示它需要 Assembly x 而不是 Assembly y 来处理数据。

The serialization/deserialization works fine, however if I were to change the assembly which does the work it fails to deserialize because of the header in the binary file indicating that it requires Assembly x instead of Assembly y to handle the data.

是否可以将序列化/反序列化设置为与程序集无关?

Is it possible to setup the serialization/deserialization to be assembly agnostic?

推荐答案

您可以控制二进制格式化程序的方式通过将自定义SerializationBinder分配给格式化程序来解析其类型。这样,您就无需弄乱AppDomain的resolve事件,从而消除了由此产生意外副作用的风险。

You can control how the binary formatter resolves its types by assigning a custom SerializationBinder to the formatter. In this way, you won't need to mess with the AppDomain's resolve events and you eliminate the risk of unexpected side effects from that.

在< a href = http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter.binder.aspx rel = noreferrer> MSDN 。

这篇关于具有不同程序集版本的二进制反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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