binaryformatter

Binary object graph serialization

筅森魡賤 提交于 2019-12-07 02:39:58
问题 I'm looking for advice on serialization in a .net app. The app is a desktop/thick client app and the serialization represents the persisted document format. The requirements for the serializer is Must allow serializing fields, not public properties only. Must not require parameterless constructors. Must handle general object graphs, i.e. not only DAG but shared/bidirectional references. Must work with framework classes (e.g. Serialize Dictionaries). Currently we use the BinaryFormatter which

Serialized objects disappearing (BinaryFormatter)

冷暖自知 提交于 2019-12-06 03:01:51
Background I have an object which I need to serialize in order to transfer to a high performance computing cluster for later use Previously, I've used the out-of-the-box binary formatter for my object which represents a statistical shape model and all worked happily My object became more complex and I decided to customize the serialization process by implementing ISerializable. I continue to support data stored in the previous format The Problem My problem is that one particular value appears to serialize successfully, but always has a value of null when I attempt deserialization. (no error,

How do you identify the field that is causing binary serialization to fail in .NET?

只谈情不闲聊 提交于 2019-12-05 23:08:06
问题 I am attempting to serialize an object graph in .NET with the following method: public static byte[] Serialize(object data) { var binary = new BinaryFormatter(); using (var ms = new MemoryStream()) { binary.Serialize(ms, data); return ms.ToArray(); } } However, I am running into the following error: FormatException: Input string was not in a correct format. Stack Trace: at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean

Binary object graph serialization

不想你离开。 提交于 2019-12-05 06:58:28
I'm looking for advice on serialization in a .net app. The app is a desktop/thick client app and the serialization represents the persisted document format. The requirements for the serializer is Must allow serializing fields, not public properties only. Must not require parameterless constructors. Must handle general object graphs, i.e. not only DAG but shared/bidirectional references. Must work with framework classes (e.g. Serialize Dictionaries). Currently we use the BinaryFormatter which handles all of the above quite well, but size/performance and version tolerance is an issue. We use the

Performance: BinaryFormatter vs. XmlSerializer

匆匆过客 提交于 2019-12-05 02:39:05
I read very often that the BinaryFormatter has better performance then XmlSerializer. Out of curiosity, I wrote a test-app. a wtf moment... why is Xml so much faster than Bin (especially the deserialization)? using System; using System.Collections.Generic; using System.Runtime.Serialization; using System.Xml.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.IO; namespace SerPlayground { class Program { static void Main(string[] args) { var items = new List<TestClass>(); for (int i = 0; i < 1E6; i++) { items.Add(new TestClass() { Name = i.ToString(), Id = i }); }

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

谁都会走 提交于 2019-12-04 12:16:26
问题 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

BinaryFormatter in netstandard 1.5

北战南征 提交于 2019-12-04 09:48:48
According to the List of .NET CoreFx APIs and their associated .NET Platform Standard version , System.Runtime.Serialization.Formatters is added into to the .NET Platform Standard since 1.3, which is cool, but when I try to create a .Net Core class library targeting netstandard1.5 under.Net Core RC2, I can't use it. The code is simple, just intending to declare a BinaryFormatter: public class Problems { private System.Runtime.Serialization.Formatters.Binary.BinaryFormatter _formatter; } Error is : Error CS0234 The type or namespace name 'Serialization' does not exist in the namespace 'System

How do you identify the field that is causing binary serialization to fail in .NET?

大城市里の小女人 提交于 2019-12-04 04:01:27
I am attempting to serialize an object graph in .NET with the following method: public static byte[] Serialize(object data) { var binary = new BinaryFormatter(); using (var ms = new MemoryStream()) { binary.Serialize(ms, data); return ms.ToArray(); } } However, I am running into the following error: FormatException: Input string was not in a correct format. Stack Trace: at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System

How do I ignore event subscribers when serializing an object?

早过忘川 提交于 2019-12-03 16:13:13
问题 When the following class is serialized with a BinaryFormatter , any objects subscribing to the Roar event will also be serialized, since references to those objects are held by the EventHandler delegate. [Serializable] public class Lion { public event EventHandler Roar; public string Name { get; set; } public float Fluffiness { get; set; } public Lion(string name, float fluffiness) { Name = name; Fluffiness = fluffiness; } public void Poke() { Roar(); // Could be null, etc.. } } How would you

BinaryFormatter alternatives

只谈情不闲聊 提交于 2019-12-03 11:51:02
问题 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