Serializing DataColumn

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!
 
J

Jan Tielens

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top