binaryformatter

Deserializing a newer version of an object from an older version of the object

我的梦境 提交于 2019-12-03 07:49:49
Suppose I had this class: [Serializable] public class SomeClass { public SomeClass() {//init} public string SomeString {get;set;} } This class gets Serialized when the application closes, and gets deserialized on the next run. Then, I built it and released the application, and now the class has changed: [Serializable] public class SomeClass { public SomeClass() {//init} public string SomeString {get;set;} public int SomeInt {get;set;} } Is there a way to set a property to its default on deserialization in case its not found in the old serialized object? One way I thought about is keeping the

BinaryFormatter alternatives

流过昼夜 提交于 2019-12-03 02:17:30
A BinaryFormatter-serialized array of 128³ doubles, takes up 50 MB of space. Serializing an array of 128³ struct s with two double fields takes up 150 MB and over 20 seconds to process. Are there fast simple alternatives that would generate compact files? My expectation is that the above examples would take up 16 and 32 MB, respectively, and under two seconds to process. I took a look at protobuf-net, but it appears that it does not even support struct arrays. PS: I apologize for making a mistake in recording file sizes. The actual space overhead with BinaryFormatter is not large. If you use a

Serialize in one assembly, and de-serialize in another?

此生再无相见时 提交于 2019-12-02 03:52:51
问题 I have the same class in two projects one is being sent on runtime to the other process that has to de-serialize that object and use it (giving that the two objects are the same but differ in assembly name so they are actually interpreted as two different types). From my research i have came with those solutions that doesn't work for the following reasons. Json.NET : giving me an exceptions that the two types aren't compatible (tried using typename.all in serialization settings). protobuf-net

ExtensionDataObject not marked as serializable

你说的曾经没有我的故事 提交于 2019-12-02 01:20:02
Oi! I'm having issues serializing my session state. We have 2 components, our WCF and Web. Based on our AdministrationPartial.cs and Administration.svc we generate "Administration.cs" code for our web project with the following .bat file : svcutil.exe http://wcf_url.local/Administration.svc?wsdl /r:"{Path}\{Namespace}.dll" /d:"{Path}\{Namespace}\Code" I removed the personal data from the above statement and replaced it with {path} and {namespace}. The Administration.cs will be inside the Code map. In the Partial we have : [Serializable] public partial class MyObject { <Some code> } It

Serialize in one assembly, and de-serialize in another?

核能气质少年 提交于 2019-12-01 22:50:21
I have the same class in two projects one is being sent on runtime to the other process that has to de-serialize that object and use it (giving that the two objects are the same but differ in assembly name so they are actually interpreted as two different types). From my research i have came with those solutions that doesn't work for the following reasons. Json.NET : giving me an exceptions that the two types aren't compatible (tried using typename.all in serialization settings). protobuf-net : requires me to add attributes every where or simply provide it with the properties name (in v2),

BinaryFormatter alternative

自古美人都是妖i 提交于 2019-12-01 21:46:33
I am shopping for a BinaryFormatter alternative/replacement. The current issues I have with BinaryFormatter (and the alternatives should address this) are 1) backwards compatibility (can deserialize Classes serialized using an earlier version) 2) size 3) speed I have checked out AltSerializer which looks ok, some conflicting reports on speed however it looks like it supports backwards compatibility. I also looked at protobuf-net which looks fantastic except at this stage it would require alot of work as you have to define all the .proto files. Perhaps someone using either of the above or

.net binary formatter deserialize an object whose definition has changed a lot

烈酒焚心 提交于 2019-12-01 21:23:20
I am trying to deserialize a file which is serialized using an older version. In the new version, We have done the following things change namespace Change class member access level, from private to public Add a new inter parent class. Class A was derived from Base. Now, Class A is derived from B, and B is derived from Base. In B, there is no new member introduced. Base class adds a new member. I know using SerializationBinder can solve issue 1. For the new added class member, I have marked with [NonSerialized]. But I still get deserialization error. Any pointers? I hate to say it, but my

C# BinaryFormatter bytes orde

て烟熏妆下的殇ゞ 提交于 2019-12-01 12:50:12
问题 I am using binary formatter in order to serialize my object. I would like to know what is the order of the properties in the serialized byte array (according to properties order in the object class? randomaly?) And if I can control the order of the bytes according to the props. For example, If I serialize the following obj: public class Human { int Age {get;set;} int Weight {get; set;} } If I will serialize it, what is the order of bytes means? (does the first 4 bytes will represent the age,

BinaryFormatter ignore assembly version

天涯浪子 提交于 2019-12-01 06:43:17
I have the following method to generate a hash of an object. It works pretty good! But when I change the version of the assembly, the hash is changing even when the object is the same. public static string GetHash(Object item) { MemoryStream memoryStream = new MemoryStream(); BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, item); binaryFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple; HashAlgorithm hashAlgorithm = new MD5CryptoServiceProvider(); memoryStream.Seek(0, SeekOrigin.Begin); return Convert.ToBase64String(hashAlgorithm

BinaryFormatter ignore assembly version

元气小坏坏 提交于 2019-12-01 06:03:33
问题 I have the following method to generate a hash of an object. It works pretty good! But when I change the version of the assembly, the hash is changing even when the object is the same. public static string GetHash(Object item) { MemoryStream memoryStream = new MemoryStream(); BinaryFormatter binaryFormatter = new BinaryFormatter(); binaryFormatter.Serialize(memoryStream, item); binaryFormatter.AssemblyFormat = FormatterAssemblyStyle.Simple; HashAlgorithm hashAlgorithm = new