Tag: binaryformatter

更改类名后是否可以通过“BinaryFormatter”恢复序列化的对象?

我使用BinaryFormatter来存储我的应用程序设置。 现在,经过几年的持续开发,在许多用户已经在使用我的应用程序之后,我想要更改几个类的命名方式以及它们所在的命名空间。 但是,如果我这样做,则不再可能加载设置,因为BinaryFormater通过其代码内名称调用事物。 因此,例如,如果我在代码MyNamespace.ClassOne MyNamespace.Class.NumberOne更改为MyNamespace.Class.NumberOne ,则无法再加载设置,因为MyNamespace.ClassOne不再存在。 我想要进行此更改并允许用户保留其设置文件。 这可能吗? 我的意思是,我想我可以研究它保存的格式,并手动更改二进制文件,替换类名,但这将是黑客的方法。 必须有一个正常的方法,对吗?

BinaryFormatter和Deserialization Complex对象

无法反序列化以下对象图。 在BinaryFormmater上调用deserialize方法时发生exception:System.Runtime.Serialization.SerializationException: The constructor to deserialize an object of type ‘C’ was not found. C上有两个构造函数,我认为问题可能是:序列化Binaryformatter使用参数化和反序列化过程,它需要一个无参数的。 有黑客/解决方案吗? 对象: [Serializable] public class A { B b; C c; public int ID { get; set; } public A() { } public A(B b) { this.b = b; } public A(C c) { this.c = c; } } [Serializable] […]