binaryformatter

Changing types during binary deserialization in C#

半城伤御伤魂 提交于 2019-11-30 23:38:07
One of the solutions in our company consumes a 3rd party service. Communication is done through XML messaging. On our end, we generate classes to be used based on XML schemas that they provide us, and at some point we serialize some of those types into a binary blob in our database for later use. The problem comes in where that 3rd party company has changed one of the fields from a boolean to an integer type. Now when we try to deserialize the data that's already there we predictably get a type conversion exception (can't convert from boolean to integer). My question is - how do we go about

ISerializable and backward compatibility

懵懂的女人 提交于 2019-11-30 20:38:34
I have to work an an old application that used binaryFormatter to serialize application data into filestream (say in a file named "data.oldformat") without any optimizazion the main class has been marked with attribute <serializable()>public MainClass ....... end class and the serialization code dim b as new binaryformatter b.serialize(mystream,mymainclass) In an attempt to optimize the serialization/deserialization process I simply made the class implement the ISerializable interface and wrote some optimized serialization routines <serializable()>public MainClass implements ISerializable ....

Changing types during binary deserialization in C#

两盒软妹~` 提交于 2019-11-30 19:32:51
问题 One of the solutions in our company consumes a 3rd party service. Communication is done through XML messaging. On our end, we generate classes to be used based on XML schemas that they provide us, and at some point we serialize some of those types into a binary blob in our database for later use. The problem comes in where that 3rd party company has changed one of the fields from a boolean to an integer type. Now when we try to deserialize the data that's already there we predictably get a

Backwards compatibility in .NET with BinaryFormatter

隐身守侯 提交于 2019-11-30 09:08:13
We use BinaryFormatter in a C# game, to save user game progress, game levels, etc. We are running into the problem of backwards compatibility. The aims: Level designer creates campaign (levels&rules), we change the code, the campaign should still work fine. This can happen everyday during development before release. User saves game, we release a game patch, user should still be able to load game The invisible data-conversion process should work no matter how distant the two versions are. For example an user can skip our first 5 minor updates and get the 6th directly. Still, his saved games

ISerializable and backward compatibility

廉价感情. 提交于 2019-11-30 05:06:17
问题 I have to work an an old application that used binaryFormatter to serialize application data into filestream (say in a file named "data.oldformat") without any optimizazion the main class has been marked with attribute <serializable()>public MainClass ....... end class and the serialization code dim b as new binaryformatter b.serialize(mystream,mymainclass) In an attempt to optimize the serialization/deserialization process I simply made the class implement the ISerializable interface and

How to get BinaryFormatter to deserialize in a different application

大憨熊 提交于 2019-11-30 04:49:49
I am using BinaryFormatter to serialize an array of class instances to a file. I can deserialize this fine within the same application. When I try the same deserialization in a different application (that pulls in a common file that does the work) then I get the following error: {"Could not load file or assembly 'pmlscan, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The module was expected to contain an assembly manifest."} where pmlscan is the name of the original application. How do I get BinaryFormatter to not try and load pmlscan? You can achieve it by

Backwards compatibility in .NET with BinaryFormatter

最后都变了- 提交于 2019-11-29 13:55:12
问题 We use BinaryFormatter in a C# game, to save user game progress, game levels, etc. We are running into the problem of backwards compatibility. The aims: Level designer creates campaign (levels&rules), we change the code, the campaign should still work fine. This can happen everyday during development before release. User saves game, we release a game patch, user should still be able to load game The invisible data-conversion process should work no matter how distant the two versions are. For

Binary Formatter and properties with\\without backing fields

落爺英雄遲暮 提交于 2019-11-29 12:11:12
I have the following class serialized into a file using BinaryFormatter: [Serializable] public class TestClass { public String ItemTwo { get; set; } public String ItemOne { get; set; } } Using this code: FileStream fs = new FileStream("DataFile.dat", FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(fs, new TestClass{ItemOne = "ItemOne", ItemTwo = "ItemTwo"}); fs.Close(); When deserializing using this code: FileStream fs = new FileStream("DataFile.dat", FileMode.Open); BinaryFormatter formatter = new BinaryFormatter(); TestClass addresses = (TestClass

Assembly Independent Serialization in .NET

橙三吉。 提交于 2019-11-29 10:19:24
I use Serialization/DeSerialization Technique. BinaryFormatter class. Each time when new assembly is created the BinaryFormatter can't Deserialize binary data even if the class structure is the same, but the Assembly version differs. Is it possible to Deserialize binary buffer with no checking the assembly version if the class structure stays unchanged? Jacob Seleznev Try this: public sealed class CurrentAssemblyDeserializationBinder : SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { return Type.GetType(String.Format("{0}, {1}", typeName, Assembly

How to get BinaryFormatter to deserialize in a different application

好久不见. 提交于 2019-11-29 00:52:13
问题 I am using BinaryFormatter to serialize an array of class instances to a file. I can deserialize this fine within the same application. When I try the same deserialization in a different application (that pulls in a common file that does the work) then I get the following error: {"Could not load file or assembly 'pmlscan, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The module was expected to contain an assembly manifest."} where pmlscan is the name of