WriteXml recursive call throws exception regarding StartAttribute c#




public void WriteXml(XmlWriter w)
{
w.WriteAttributeString("Name", Name);

w.WriteAttributeString("Type", GetType().Name);

w.WriteStartElement("Actions");

foreach (object obj in Actions)
{
if (obj is IAction)
{
XmlSerializer itemxml = new XmlSerializer(obj.GetType());

itemxml.Serialize(w, obj);
}
else if (obj is ActionGroup)
{
var group = obj as ActionGroup;
group.WriteXml(w);
}
}

w.WriteEndElement();
}


I've got the above code in my ActionGroup class. An ActionGroup contains actions and actiongroups. When I try to serialize it, any group beyond the first level throws an exception as soon as it hits the first line of the method.


"Token StartAttribute in state Content would result in an invalid XML document."


No comments:

Post a Comment