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
0
votes
2 answers

How to deserialize the data which is already serialized using BinaryFormatter in C#?

I have a ConcurrentDictionary which I serialized using the BinaryFormatter using the below code. ConcurrentDictionary _jobsAck; var binaryFormatter = new BinaryFormatter(); using (var stream = File.Open(BINARY_FILENAME,…
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197
0
votes
1 answer

c#: Retrieve BinaryLibrary from binary serialization

I am trying to get the BinaryLibrary value stored in a binary serialization (BinaryFormatter). I've been following outline from here. I tried a naive: FileStream fs = new FileStream("binary.dat", FileMode.Open); try { …
malat
  • 12,152
  • 13
  • 89
  • 158
0
votes
1 answer

Share a method in task and normal function without using lock in C#

I'm developing ASP .Net core application to communicate with USB Serial device to read/write device information using binary serializer. Moreover, I have created a common wrapper project to communicate with hardware using SerialPortStream and…
Emily
  • 89
  • 8
0
votes
3 answers

C# and Android/Java - cross-language binary stream writers/readers? (for primitives and UTF-8 strings)

What is the easiest way to do binary serialization/deserialization of some custom data between C# and Android's Java? I'd like to find for Java something similar to C# BinaryWriter and BinaryReader - which supports writing primitives (like uint16)…
tomash
  • 12,742
  • 15
  • 64
  • 81
0
votes
0 answers

Serialize non-primitive objects using BinaryWriter

I would like to use the System.IO.BinaryWriter to serialize data structure with non-primitive fields\properties. I know that this serializer can work only with primitive types, so I need to "dig-in" into each object. I assumed that the BinaryWriter…
Guy E
  • 1,775
  • 2
  • 27
  • 55
0
votes
1 answer

Binary serialization and deserialization of decimal type in c#

In order to binary serialize a decimal type I do the following: var ms = new MemoryStream(); decimal d = 123.45M; int[] bits = Decimal.GetBits(d); for(int i=0; i<4; i++) ms.Write(BitConverter.GetBytes(bits[i]),0,4); Now that I have a int[] bits…
Tono Nam
  • 34,064
  • 78
  • 298
  • 470
0
votes
3 answers

C# serialize only values into a byte stream

Is there any possibility to automatically serialize properties of a class into a byte[] array or stream. Stream stream = File.Open(@"C:/traiBin.bin", FileMode.Create); BinaryFormatter bFormatter = new BinaryFormatter(); bFormatter.Serialize(stream,…
0
votes
1 answer

Deserializing a byte[] back into a DataTable

I have the following code to serialize /deserialize a DataTable: public static byte[] Serialize(DataTable dt) { System.IO.MemoryStream stream = new System.IO.MemoryStream(); System.Runtime.Serialization.IFormatter formatter =…
Sean Thoman
  • 7,429
  • 6
  • 56
  • 103
0
votes
1 answer

Custom equality comparer for `BinaryFormatter`

TL;DR; My custom [Serializable] class overrides GetHashCode and Equals, so multiple distinct objects can be "equal", and it looks like BinaryFormatter calls OnSerialized only once, but calls OnDeserialized twice when two equal but distinct…
LOST
  • 2,956
  • 3
  • 25
  • 40
0
votes
1 answer

Is Castle Dynamic Proxy IInvocation really different in .net Core and Framework?

I have code that uses Castle DynamicProxy to proxy code invocation. In Intercept(IInvocation invocation), I use NewtonSoft to Json serialize the invocation. Newtonsoft.Json.JsonConvert.SerializeObject(invocation.Method); In Framework this…
0
votes
0 answers

C# binary serialization of List, issues with _version

List has a private int field called _version that increments every time you perform an operation on the list. Unfortunately for me this field is also serialized during binary serialization, so two lists with identical content can generate…
Björn Morén
  • 693
  • 5
  • 14
0
votes
2 answers

XSD based binary serialisation

Hello i am looking for an binary serialisation for java that: - use xsd for schema - output very small byte streams - the byte stream should not contain the field names and data types - pojos should be generated like it is possible gor jaxb - nice…
GreenRover
  • 1,486
  • 1
  • 14
  • 33
0
votes
1 answer

Error during class serialization: type is not marked serializable

I have a class marked as [Serializable]. It has a property tha I don't wan to serialize. But at runtime I got an error during serialization. These are my classes: public interface IMyNonSerializable { ... } public class MyNonSerializable :…
Lorenzo Isidori
  • 1,809
  • 2
  • 20
  • 31
0
votes
1 answer

Why C++ msgpack-c adds number 13 (0x0D) before number 10 (0x0A), but C# MessagePack-CSharp does not?

I was trying to use MessagePack to serialize integers from 0 to 127 in C++ and in C# on Windows, but the results are not the same. msgpack-c inserts 0x0D between 0x09 and 0x0A, but MessagePack-CSharp does not. Why is that? OS: Windows 10 IDE: Visual…
Jinjinov
  • 2,554
  • 4
  • 26
  • 45
0
votes
3 answers

Is there a chance of saving the hashcode of an object during its binary serialization (binary)?

I want to be able to compare objects by the hashcode. Per example, one is the object itself, and the other is serialized (binary) and then recovered version of the object. How can I save the hash in the serialized (binary) object?
marcelo-ferraz
  • 3,147
  • 4
  • 38
  • 55