Serializing DataColumn

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I'm having trouble Serializing a System.Data.DataColumn
object. When I try to serialize it, I get the following:

System.NotSupportedException: Cannot serialize member
System.ComponentModel.MarshalByValueComponent.Site of
type System.ComponentModel.ISite because it is an
interface.

I tried a number of workarounds without sucess:

1. I tried subclassing DataColumn with my own class,
overriding the Site property and setting the
[XMLIgnoreAttribute] on the Site property.

2. I tried creating an XML serialization override:

XmlAttributeOverrides xOver = new XmlAttributeOverrides();
XmlAttributes attrs = new XmlAttributes();

attrs.XmlIgnore = true;
xOver.Add(typeof(DMSDataColumn), "Site", attrs);

XmlSerializer mySerializer = new XmlSerializer(typeof
(DataColumn), xOver);

Neither of the above worked--both issued threw the same
exception about not being able to serialize Site. It
seems as though the XML Serializer is hellbent on trying
to serialize the Site property no matter what I do to
tell it to ignore Site.

I know there is the option of serializing the DataColumn
indirectly by serializing a DataSet. This option will
not work for me as I do not want to serialize all the
columns and rows of the DataTable. I just want to
serialize one DataColumn in the DataTable.

Please help!

Thanks!
 
You could copy the DataColumn to an empty DataSet, and serialize the
DataSet. Afterwards you could get the column out of the DataSet. I know that
this is not a nice solution, but it will probably work...
 
Back
Top