binary-serialization

deserializing a generic list returns null

I'm de/serializing an object like so: public class myClass : ISerializable { public List<OType> value; public myClass(SerializationInfo info, StreamingContext context) { this.value = (List<OType>)info.GetValue("value", typeof(List<OType>)); } void ISerializable.GetObjectData(SerializationInfo info, StreamingContext conte...

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 differences between the two. The genesis of my curiosity lies in why the BinaryFormatter is ab...

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 NameValueCollection FieldErrors { get { return _fieldErrors; } set { _fieldErrors = ...

Convert a byte[] array into DataTable

I saved an object of type DataTable into SQL 2005 database in a field of type varbinary. I want to retrieve it back but I wasn't able to type cast it. This is how i saved it. MemoryStream memStream = new MemoryStream(); StreamWriter sw = new StreamWriter(memStream); sw.Write(dt); con.Open(); using (SqlCommand cmd = new SqlCommand("...

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 value for address exists */) address = info.GetString("address"); } publ...

Is there an XML specific object (like XElement) that is binary serializable?

I have a use case where I am serializing objects over the wire via MSMQ (mostly strings). When I read the object off the queue I want to be able to tell if the user meant for the object to be a XML or a string. I was thinking a good way to do this would just be to check the type. If it's XmlElement than it becomes XML data otherwise it...

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 compile with the following error: <NonSerialized()> Public Event PropertyValueChanged() re...

Why can't the 'NonSerialized' attribute be used at the class level? How to prevent serialization of a class?

I have a data object that is deep-cloned using a binary serialization. This data object supports property changed events, for example, PriceChanged. Let's say I attached a handler to PriceChanged. When the code attempts to serialize PriceChanged, it throws an exception that the handler isn't marked as serializable. My alternatives: I...

How to optimize class for viewstate

If I have an object I need to store in viewstate, what kinds of things can I do to optimize the size it takes to store the object? Obviously storing the least amount of data will take less space, but aside from that, are there ways to architect the class, properties, attrbutes etc, that will effect how large the serialized output is? ...

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 recursive references - so I'm wondering whether the BinaryFormatter is actually storing multipl...

Best method for serializing objects in .NET (as of v4.0)

I have an simple custom object called MyObject (a couple of basic properties and a List(of MyObject), so it's recursive) that I need to serialize for storage. I'm not sure if I'll serialize to XML or Binary yet, but I want to make sure I'm using the most up-to-date methods for doing it, as there are a few different namespaces involved an...

Converting binary serialization to Soap serialization

I want to send binary serialized messages, but I am worried that if there is an error when de-serializing, I won't be able to figure out the problem. For SOAP, I would just be able to see the messages, but I don't want all of the CPU overhead for XML processing of SOAP messages. The other problem with SOAP messages is that they fail if...

Is there a shortcut to binary-serialize every property in an object?

Hi, If there is an object in which every public property must be serialized and properties are simple (just numbers or strings or objects already implementing ISerializable), is there an easy way to do it without having to create GetObjectData(SerializationInfo info, StreamingContext context) and a constructor taking SerializationInfo a...

Sending interfaces as message in NServiceBus with the Binary Serializer

I recently moved to using the binary serializer to send messages with NServiceBus. My messages are all defined as interfaces and are instantiated using bus.Send<MessageType>(msg => msg.Property = someValue) This leads to an exception being thrown from NServiceBus stating that Cannot create an instance of an interface I can ...

polymorphism in c and buffers

I have this union: typedef union Message { message_base base; message_with_parameters parameters; reply_message reply; buffer_t *buffer; // can't figure out what to put here } message; message_with_parameters has a message_base as the first field and reply_message has a message_wit...

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 { public static int constructionCount = 0; public Car() { construction...

binary serialization, adding a new field to class - will it work?

I have a client and a server application which communicate over .NET 2.0 Remoting using binary serialization. A small change has been made to one of the data transfer object's interface and the implementing class, well, an array of strings field was added. If I to redeploy a new version of server application, will my old clients cont...

Conditional C# Binary Serialization

I am using BinaryFormatter to serialize a class and its variables by condition. For example: [Serializable] public class Class1 { private Class2 B; ... } [Serializable] public class Class2{...} I want the variable B to be serialized only when remoting time, but not when i serialize it to file storage. Questions: 1) I know that in Xml...

getting "unable to find assembly" when trying to deserialize, works from client to server but not the other way

Hello, I've read plenty of similar questions and answers on this topic, but still not sure why I get this problem. I have a client and server projects, both using the same dll library I created. when I serialize an object on the client, I have no problem deserializing it on the server, however when I try to deserialize it on the client ...

Binary Serialized File - Delphi

I am trying to deserialize an old file format that was serialized in Delphi, it uses binary seralization. I know nothing about the structure of the file except some very high level records that are in it. What steps would you take to solve this problem? Any tools etc? ...