I'm trying to serialize, via the XmlSerializer, an object which is derived
from System.Windows.Forms.Control. It throws an exception complaining about
not being able to serialize the Site property. I expected problems and my
plan was to work through them one at a time supplying an XmlIgnore attribute
for each of the properties it had problems with. However, for some reason
this doesn't seem to work. The code is below. Does anyone know why it's
still throwing the exception complaining about the Site property after
specifying the XmlIgnore attribute for that property?
using System;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.IO;
using System.Drawing;
public class MyControl : Control
{
public MyControl()
{
}
}
public class Application
{
public static void Main()
{
MyControl control = new MyControl();
XmlSerializer serializer;
XmlAttributes attributes;
XmlAttributeOverrides overrides;
overrides = new XmlAttributeOverrides();
attributes = new XmlAttributes();
attributes.XmlIgnore = true;
overrides.Add(typeof(MyControl), "Site", attributes);
control.Font = new Font("Arial", 12);
serializer = new XmlSerializer(typeof(MyControl), overrides);
serializer.Serialize(Console.OpenStandardOutput(), control);
}
}
--
Thanks,
Nick
|