binaryformatter

deserialize system.outofmemoryexception on a networkstream

时光毁灭记忆、已成空白 提交于 2020-01-07 05:09:14
问题 I've got a serializeable class called Cereal with several public fields shown here <Serializable> Public Class Cereal Public id As Integer Public cardType As Type Public attacker As String Public defender As String Public placedOn As String Public attack As Boolean Public placed As Boolean Public played As Boolean Public text As String Public Sub New() End Sub End Class My client computer is sending a new Cereal to the host by serializing it shown here 'sends data to host stream (c1) Private

C# [anonymous\generic] object to byte[] without BinaryFormatter [in .NET 4.5]?

喜欢而已 提交于 2020-01-04 02:15:14
问题 BinaryFormatter works great, but doesn't exist in Portable class libraries for .NET 4.5. I've read that it IS in .NET 4.6 Portable. I have not confirmed this because when I change to 4.6 in my project settings, I get a warning message that "4.5 will be automatically targeted" unless I de-select Silverlight, WindowsPhone, Windows Universal, Xamarin, etc), so I can only target .NET 4.6 Portable if I'm NOT targeting additional platforms, thus defeating the purpose. Here is my original

BinaryFormatter - Is it possible to deserialize known class without the assembly?

会有一股神秘感。 提交于 2020-01-02 10:22:13
问题 I am currently trying to interoperate with a program that sends data over the network after first formatting it with C#'s BinaryFormatter. It's a dumb idea, and I hate it, but I have to interoperate with it. I know what the type looks like, I know it's exact layout. But I can't add a reference to that specific assembly in my program for various reasons. Given how tightly coupled BinaryFormatter is to the specific type/version, I can't seem to find a way to get it to deserialize despite

Issue deserializing encrypted data using BinaryFormatter

廉价感情. 提交于 2019-12-31 03:09:03
问题 Here is my code: public static void Save<T>(T toSerialize, string fileSpec) { BinaryFormatter formatter = new BinaryFormatter(); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); using (FileStream stream = File.Create(fileSpec)) { using (CryptoStream cryptoStream = new CryptoStream(stream, des.CreateEncryptor(key, iv), CryptoStreamMode.Write)) { formatter.Serialize(cryptoStream, toSerialize); cryptoStream.FlushFinalBlock(); } } } public static T Load<T>(string fileSpec) {

Deserialization of optional fields from BinaryFormatter

二次信任 提交于 2019-12-30 10:08:10
问题 I have an application that serializes data using BinaryFormatter . A member was added to the class that was serialized from one version to the next without changing the class name. Code was added to handle the possible absence of the added member in old serialized files: private void readData(FileStream fs, SymmetricAlgorithm dataKey) { CryptoStream cs = null; try { cs = new CryptoStream(fs, dataKey.CreateDecryptor(), CryptoStreamMode.Read); BinaryFormatter bf = new BinaryFormatter(); string

hooking into the deserialization process

自古美人都是妖i 提交于 2019-12-24 15:07:11
问题 I have a DateRange object that represents the notion of Infinity via Static reference as shown below. As you see, the end points that define Infinity are also static references in a different class, DatePoint.Past and DatePoint.Future . Now I need to serialize this (as part of a deep Clone method that uses serialization) and know when it's deserialized that an instance with DateTime.Min and DateTime.Max as endpoints then the instance should be DateRange.Infinity . So I think I need to make it

memorystream copyto network stream issues

吃可爱长大的小学妹 提交于 2019-12-24 06:49:33
问题 I'm having a problem with this code here. using (MemoryStream ms = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(ms,SerializableClassOfDoom); ms.Position = 0; byte[] messsize = BitConverter.GetBytes(ms.Length); ms.Write(messsize, 0, messsize.Length); NetworkStream ns = Sock.GetStream(); ms.CopyTo(ns); //ms.Close(); } I can't figure out what's happening here, or why it's not working. It seems like eather it doesn't copy, or it closes the network stream, or

serialize/deserialize a list of objects using BinaryFormatter

醉酒当歌 提交于 2019-12-23 20:19:47
问题 I know there were already many discussions on that topic, like this one: BinaryFormatter and Deserialization Complex objects but this looks awfully complicated. What I'm looking for is an easier way to serialize and deserialize a generic List of objects into/from one file. This is what I've tried: public void SaveFile(string fileName) { List<object> objects = new List<object>(); // Add all tree nodes objects.Add(treeView.Nodes.Cast<TreeNode>().ToList()); // Add dictionary (Type: Dictionary

How to increase deserialization speed?

时间秒杀一切 提交于 2019-12-23 09:38:05
问题 Serializing/deserializing with BinaryFormatter, resulting serialized file is ~80MB in size. The deserialization takes a few minutes. How could I improve on this? Here's the deserialization code: public static Universe DeserializeFromFile(string filepath) { Universe universe = null; FileStream fs = new FileStream(filepath, FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); try { universe = (Universe)bf.Deserialize(fs); } catch (SerializationException e) { Console.WriteLine("Failed to

Serialized objects disappearing (BinaryFormatter)

强颜欢笑 提交于 2019-12-22 09:31:04
问题 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