Questions tagged [binary-serialization]

The process of translating data structures or object state into a binary format

Serialization can be defined as the process of storing the state of an object to a storage medium. During this process, the public and private fields of the object and the name of the class, including the assembly containing the class, are converted to a stream of bytes, which is then written to a data stream. When the object is subsequently deserialized, an exact clone of the original object is created.

http://en.wikipedia.org/wiki/Serialization
http://msdn.microsoft.com/en-us/library/72hyey7b(v=vs.110).aspx

178 questions
51
votes
5 answers

What are the differences between the XmlSerializer and BinaryFormatter

I spent a good portion of time last week working on serialization. During that time I found many examples utilizing either the BinaryFormatter or XmlSerializer. Unfortunately, what I did not find were any examples comprehensively detailing the…
ahsteele
  • 26,243
  • 28
  • 134
  • 248
46
votes
4 answers

How to analyse contents of binary serialization stream?

I'm using binary serialization (BinaryFormatter) as a temporary mechanism to store state information in a file for a relatively complex (game) object structure; the files are coming out much larger than I expect, and my data structure includes…
Tao
  • 13,457
  • 7
  • 65
  • 76
32
votes
2 answers

Does protobuf-net have built-in compression for serialization?

I was doing some comparison between BinaryFormatter and protobuf-net serializer and was quite pleased with what I found, but what was strange is that protobuf-net managed to serialize the objects into a smaller byte array than what I would get if I…
theburningmonk
  • 15,701
  • 14
  • 61
  • 104
26
votes
3 answers

How does BinaryFormatter.Deserialize create new objects?

When BinaryFormatter deserializes a stream into objects, it appears to create new objects without calling constructors. How is it doing this? And why? Is there anything else in .NET that does this? Here's a demo: [Serializable] public class Car { …
Joe Daley
  • 45,356
  • 15
  • 65
  • 64
26
votes
6 answers

Is it possible to do .NET binary serialization of an object when you don't have the source code of the class?

I am using BinaryFormatter to do binary serialization of some objects in C#. However, some of the objects contain classes that I access via a DLL and do not have the source code for, so I can't mark them with the Serializable attribute. Is there a…
Craig W
  • 4,390
  • 5
  • 33
  • 51
17
votes
2 answers

JavaScript to C# Numeric Precision Loss

When serializing and deserializing values between JavaScript and C# using SignalR with MessagePack I am seeing a bit of precision loss in C# on the receiving end. As an example I am sending the value 0.005 from JavaScript to C#. When the…
TGH
  • 38,769
  • 12
  • 102
  • 135
17
votes
10 answers

BinaryFormatter.Deserialize "unable to find assembly" after ILMerge

I have a C# solution with a referenced dll (also C# with the same .Net version). When I build the solution and run the resulting exe, without merging the exe and the referenced dll, everything works fine. Now I want to merge these into one exe. I…
Mike Park
  • 10,845
  • 2
  • 34
  • 50
17
votes
3 answers

How to ignore Event class member for binary serialization?

I need to avoid serializing an Event class member because when the event is handled by an object that is not marked as Serializable the serialization will fail. I tried using the NonSerialized attribute on the Event class member but it fails to…
Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
16
votes
3 answers

Test for Optional Field when using .NET Custom Serialization

Given a class like this one: [Serializable] public class MyClass { string name; string address; public MyClass(SerializationInfo info, StreamingContext context){ name = info.GetString("name"); if(/* todo: check if a…
Agnel Kurian
  • 57,975
  • 43
  • 146
  • 217
15
votes
3 answers

When should I use XML Serialization vs. Binary Serialization in the .NET framework?

I'm confused - when should I be using XML Serialization and when should I be using Binary Serialization in the .NET framework?
Shashi
  • 2,860
  • 2
  • 34
  • 45
13
votes
4 answers

DeflateStream doesnt work on MemoryStream?

I have the following piece of code: MemoryStream resultStream = new MemoryStream(); string users = ""//Really long string goes here BinaryFormatter bFormatter = new BinaryFormatter(); using (MemoryStream assignedUsersStream = new MemoryStream()) { …
Leonardo
  • 10,737
  • 10
  • 62
  • 155
11
votes
2 answers

Does removing existing field from protobuf message cause issues?

I am having one protobuf message - message Sample{ string field1 = 1; string field2 = 2; string field3 = 3; } These messages are stored in datastore in binary format. So if I want to remove any of the defined field in the above message…
9
votes
3 answers

How to create a SerializationBinder for the Binary Formatter that handles the moving of types from one assembly and namespace to another

The context is as follows I want to refactor code by moving it around to different projects Some of this code comprises of serializable DTOs that are used to send and receive data across multiple endpoints If I move the code around, serialization…
Mark
  • 5,223
  • 11
  • 51
  • 81
9
votes
1 answer

Binary serialization vs. JSON vs. xml

Does anyone know what are approximately the performance gains, in terms of time, when using binary serialization versus JSON versus xml and sending the data over the network, provided that the data structures have a lot of small (string) fields? To…
Clara
  • 2,935
  • 6
  • 34
  • 49
9
votes
4 answers

How do I deserialize old data for a type that has changed?

I have data that has been stored using binary serialization for the following class: [Serializable] public abstract class BaseBusinessObject { private NameValueCollection _fieldErrors = new NameValueCollection(); protected virtual…
ramnik
  • 545
  • 2
  • 11
1
2 3
11 12