binaryformatter

Binary Deserialization with different assembly version

寵の児 提交于 2019-11-28 20:19:56
I have a project which uses BinaryFormatter to serialize a collection of structs with string and bool? datatypes. The serialization/deserialization works fine, however if I were to change the assembly which does the work it fails to deserialize because of the header in the binary file indicating that it requires Assembly x instead of Assembly y to handle the data. Is it possible to setup the serialization/deserialization to be assembly agnostic? You can control how the binary formatter resolves its types by assigning a custom SerializationBinder to the formatter. In this way, you won't need to

Dictionary is empty on deserialization

余生颓废 提交于 2019-11-28 13:44:57
I'm currently writing a bidirectional map class, and I'm having some troubles with the serialization/deserialization of the class (question at bottom). Here's the parts of the class that's relevant. /// <summary> /// Represents a dictionary where both keys and values are unique, and the mapping between them is bidirectional. /// </summary> /// <typeparam name="TKey"> The type of the keys in the dictionary. </typeparam> /// <typeparam name="TValue"> The type of the values in the dictionary. </typeparam> [Serializable] public class BidirectionalDictionary<TKey, TValue> : IDictionary<TKey, TValue

SerializationBinder with List<T>

烂漫一生 提交于 2019-11-28 11:10:34
I'm trying to make the BinaryFormatter work across different versions of my assembly. The actual class I want to deserialize to is exactly the same in each assembly version, but on deserialization, because the objects are serialized include the assembly name they came from, the BinaryFormatter is complaining that it can't find the right assembly. So I created a custom SerializationBinder that tells the BinaryFormatter to always deserialize to the current assembly version. My scheme works and can deserialize objects correctly, but it doesn't work if my object is a List of T, where T was a type

How to convert image into binary format in iOS?

匆匆过客 提交于 2019-11-28 08:48:13
I am working on a project where I need to upload image to my server. I want to store my image's binary data to BLOB data type field in database. Therefore I need to convert my image into binary format. So that it can be saved on servers database. So How to convert an image into binary format? Please advise. You can use the CoreGraphics ' method UIImagePNGRepresentation(UIImage *image) , which returns NSData and save it. and if you want to convert it into again UIImage create it using [UIimage imageWithData:(NSData *data)] method. Demo to send your UIImage to Server - (void)sendImageToServer {

Binary Formatter and properties with\without backing fields

纵然是瞬间 提交于 2019-11-28 05:29:41
问题 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",

.Net Where to find the official specification of the BinaryFormatter serialization format?

非 Y 不嫁゛ 提交于 2019-11-27 21:13:10
I'd like to know what is the serialization format of the BinaryFormatter. I found this site which give some good informations, but it was obtained by reverse engineering and it is not complete. Where can I find the official specification of the BinaryFormatter serialization format? [MS-NRBF]: .NET Remoting: Binary Format Data Structure 来源: https://stackoverflow.com/questions/2044111/net-where-to-find-the-official-specification-of-the-binaryformatter-serializati

C# Object Binary Serialization

十年热恋 提交于 2019-11-27 19:01:23
I want to make a binary serialize of an object and the result to save it in a database. Person person = new Person(); person.Name = "something"; MemoryStream memorystream = new MemoryStream(); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(memorystream, person); How can I transform memorystream in a string type to be saved in database, and after this to be able to deserialize the object? What you're really asking for is a safe way of representing arbitrary binary data as text and then converting it back again. The fact that it stores a serialized object is irrelevant. The answer is

Why is BinaryFormatter trying to serialize an Event on a Serializable class?

最后都变了- 提交于 2019-11-27 17:54:41
问题 I have a simple class that is marked as Serializable, and it happens to have an event. I tried to mark the event member as NonSerialized, however the compiler complains. Yet when I go to serialize the class instance, the BinaryFormatter throws an exception that the event is non serializable. Does that mean you can't serialize classes that have events? If so, then the compiler should say so up front. Stream file = File.Open("f", FileMode.Open); BinaryFormatter bf = new BinaryFormatter();

BinaryFormatter and Deserialization Complex objects

跟風遠走 提交于 2019-11-27 14:18:56
Can not deserialize following object graph. That Exception occurs when deserialize method called on BinaryFormmater: System.Runtime.Serialization.SerializationException : The constructor to deserialize an object of type 'C' was not found. There're two constructor on C. and I think the problem may be : While serialization Binaryformatter using the paramatered one and on deserialization process, it needs a parameterless one. Is there a hack / solution? Objects : [Serializable] public class A { B b; C c; public int ID { get; set; } public A() { } public A(B b) { this.b = b; } public A(C c) { this

Binary Deserialization with different assembly version

荒凉一梦 提交于 2019-11-27 13:03:20
问题 I have a project which uses BinaryFormatter to serialize a collection of structs with string and bool? datatypes. The serialization/deserialization works fine, however if I were to change the assembly which does the work it fails to deserialize because of the header in the binary file indicating that it requires Assembly x instead of Assembly y to handle the data. Is it possible to setup the serialization/deserialization to be assembly agnostic? 回答1: You can control how the binary formatter