binaryformatter

SerializationBinder with List<T>

邮差的信 提交于 2019-11-27 05:58:23
问题 I'm trying to make the BinaryFormatter work across different versions of my assembly. The actual class I want to deserialize to is exactly the same in each assembly version, but on deserialization, because the objects are serialized include the assembly name they came from, the BinaryFormatter is complaining that it can't find the right assembly. So I created a custom SerializationBinder that tells the BinaryFormatter to always deserialize to the current assembly version. My scheme works and

C# Object Binary Serialization

旧城冷巷雨未停 提交于 2019-11-26 22:45:39
问题 I want to make a binary serialize of an object and the result to save it in a database. Person person = new Person(); person.Name = "something"; MemoryStream memorystream = new MemoryStream(); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(memorystream, person); How can I transform memorystream in a string type to be saved in database, and after this to be able to deserialize the object? 回答1: What you're really asking for is a safe way of representing arbitrary binary data as text

Is it possible to recover an object serialized via “BinaryFormatter” after changing class names?

狂风中的少年 提交于 2019-11-26 17:51:19
问题 I was using BinaryFormatter to store my application settings. Now, several years into continued development, after many users are already using my application, I want to change how several classes are named and in what namespaces they are located. However, if I do that, it is no longer possible to load the settings, because BinaryFormater calls things by their in-code names. So, for example, if I change MyNamespace.ClassOne to MyNamespace.Class.NumberOne in code, I can no longer load the