XmlAnyElement deserialization bug??

G

Guest

When I try to deserialize a class that has an [XmlAnyElement] property, that
is getting assigned twice. Anyone else ever encounter this? Is this a .net
bug?

Sample code to reproduce:

// -------------------------------
// Deserialize my object...
MyItem q = MyItem.FromXml(
"<MyItem Name=\"Joe\"><Property Name=\"first\"/></MyItem>" );
// -------------------------------

public class MyItem
{
public MyItem() {}

[XmlAnyElement]
public XmlElement[] SerializationElements
{
get
{
return elements;
}

set
{
elements = value; // <<--THIS GETS CALLED TWICE
}
}

public static MyItem FromXml( string xml )
{
System.IO.StringReader reader = new System.IO.StringReader( xml );
return s.Deserialize( reader ) as MyItem;
}

private XmlElement[] elements = null;
private static XmlSerializer s = new XmlSerializer( typeof(MyItem) );
}
 

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