binaryformatter

How to serialize & deserialize static reference object?

半世苍凉 提交于 2019-12-13 04:10:51
问题 i want to serialize & deserialize a object (this object has reference) using BinaryFormatter. i have expected that 'DeserializedObject.Equals(A.Empty)' is same to below code. but, a result is different. in order to 'DeserializedObject == A.Empty', how to use serialize/deserialize ? [Serializable] public class A { private string ID = null; private string Name = null; public A() { } public static A Empty = new A() { ID = "Empty", Name = "Empty" }; } class Program { static void Main(string[]

Deserialization with binaryformatter

我只是一个虾纸丫 提交于 2019-12-13 01:13:35
问题 I have a program that serializes an object and sends it over a network: TcpClient client = new TcpClient(); client.ReceiveTimeout = 10000; client.SendTimeout = 10000; IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8888); client.Connect(serverEndPoint); BinaryFormatter binaryformatter = new BinaryFormatter(); NetworkStream networkStream = client.GetStream(); if (networkStream.CanWrite) { binaryformatter.Serialize(networkStream, kort); } And on the other side I receive

Reference integrity in BinaryFormatter

99封情书 提交于 2019-12-12 09:36:58
问题 The existence of AsReference option in Protobuf-net and the word that BinaryFormatter is a "graph serializer" lead me to assume that BinaryFormatter does not maintain references and that it makes a copy of every object. But I did some tests and found out that all references in a single BinaryFormatter Serialize() or Deserialize() call are maintained even for recursive referencing. Can I confirm that BinaryFormatter does indeed maintain references? How is this different from Protobuf-net?

Load Binary Formatter file in Universal app

浪子不回头ぞ 提交于 2019-12-12 04:00:03
问题 I have an application build with .NET 4.0 and I want to port this application to a Windows 10 application. In the old application I saved my data to a binary file using Binary Formatter. using (FileStream fs2 = File.Create(serializationFile)) { var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); bformatter.Serialize(fs2, transactionData); } With the following class that is serialized: [Serializable] public class TransactionData { public TransactionData() { }

BinaryFormatter: SerializationException

陌路散爱 提交于 2019-12-11 19:33:33
问题 I'm using BinaryFormatter to load & save my treeView. I want to prevent errors if destination file doesn't exist. My code: public static void Load(TreeView tree, string filename) { if (!File.Exists(filename)) { Stream file = File.Create(filename); return; } else { using (Stream file = File.Open(filename, FileMode.Open)) { BinaryFormatter bf = new BinaryFormatter(); object obj = bf.Deserialize(file); TreeNode[] nodeList = (obj as IEnumerable<TreeNode>).ToArray(); tree.Nodes.AddRange(nodeList);

How to Ignore a property from being serialized using BinaryFormatter?

做~自己de王妃 提交于 2019-12-11 01:35:48
问题 [Serializable] class DOThis { private string _name; public string Name { get { return _name; } set { _name = value; } } public string Value { get { if (_name == "Hi") return "Hey Hi"; else return "Sorry I dont know you"; } } } I have the above class to be serialized using BinaryFormatter. Below is the serialization code, DOThis obj = new DOThis(); obj.Name = "Ho"; BinaryFormatter bfm = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bfm.Serialize(ms, obj); Here how to ignore the

Can I serialize an object (containing members: Dictionary, List… etc) in Mono and deserialize it in MS.NET or vice versa by using protobuf-net?

有些话、适合烂在心里 提交于 2019-12-10 16:27:44
问题 I have a server running on MS.NET and a client on Mono (this is a Unity3D engine) and when i try to BinaryFormatter().Deserialize an object like this: [Serializable] public class Simulator { public IDictionary<int, Task> tasks = new Dictionary<int, Task>(); the client side cannot found/load types: Dictionary, List... The same "client code" running under MS.NET works good i.e. does not have any exceptions during deserialization. As i read from http://www.mono-project.com/FAQ:_Technical

Serialization taking too much time

孤街浪徒 提交于 2019-12-10 11:16:56
问题 Here is code which takes almost 3 to 8 sec for serialization depends on object type. I want to store this result into Redis for caching. But this operation is taking too long. Also same for deserialization. public byte[] SerializeObject(object objectToSerialize) { try { //If object to serialize is null then return null if (objectToSerialize == null) return null; byte[] result; //Create memory stream and use it for Serializing object using (var ms = new MemoryStream()) { using (var zs = new

Performance: BinaryFormatter vs. XmlSerializer

℡╲_俬逩灬. 提交于 2019-12-10 03:26:40
问题 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

Performance issue when serializing multi-dimensional arrays using BinaryFormatter in .NET

流过昼夜 提交于 2019-12-08 13:39:30
问题 I'm using the BinaryFormatter to serialize a fairly simple multi-dimentional array of floats, although I suspect that the problem occurs with any primitive types. My multi-dimensional array contains 10000x16 floats (160k) and serializing on my PC runs at ~8 MB/s (60 second benchmark writing ~500 MB to SSD drive). Code: Stopwatch stopwatch = new Stopwatch(); float[,] data = new float[10000 , 16]; // Two-dimensional array of 160,000 floats. // OR float[] data = new float[10000 * 16]; // One