Home > Uncategorized > Datatables, Datasets and the XmlSerializer

Datatables, Datasets and the XmlSerializer

Yesterday I had a discussion with Manu on whether we can serialize a datatable or not. The answer depends on what serialization are we talking about.

One is formatter based (which .NET Remoting uses).

One is XmlSerializer based (which Web Services use).

Formatter based serialization is using the [Serializable] attribute / ISerializable interface.

XmlSerializer based serialization is for simple classes with no circular references. What if a class has circular references? It cannot be serialized by the XmlSerializer. A Dataset DataTable pair is an example for a circular reference. A Dataset can be serialized by the XmlSerializer whereas a DataTable cannot, because a Dataset implements IXmlSerializable. (Well this was w.r.t. 1.1, in 2.0 even the DataTable implements IXmlSerializable)

Another main difference between formatter based and XmlSerializer based serialization is that

Formatters persist the state of an object (private and protected fields inclusive). XmlSerailizer only works with public attributes / properties.

Another important thing about datasets and datables is that how the Binary Formatter handles them. Regardless of the formatter being used, the DataSet always serializes first to XML. This is because that’s how the ISerializable has been implemented by the DataSet.

Binary Serialization of DataSets

Why the DataTable is not Serializable using the XmlSerializer

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: