I am trying to deserialize a "SearchRecordList" class using the DataContractSerializer and keep getting the exception:
System.InvalidOperationException: No corresponding start element is open.
The XML i am receiving looks like this:
<?xml version=\"1.0\" encoding=\"UTF-8\"?><records type=\"array\" count=\"0\"/>
What is strange, is that if i run a test, and pass this XML string:
<?xml version=\"1.0\" encoding=\"UTF-8\"?><records type=\"array\" count=\"0\"></records>
It works fine. Any ideas what I am doing wrong? Below is the class I am deserializing to (C#, .NET 4.0):
[XmlRoot(Namespace = "", ElementName = "records", DataType = "array")]
public class SearchRecordList:List<SearchRecord>, IXmlSerializable
{
#region IXmlSerializable Members
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml(System.Xml.XmlReader reader)
{
var navigator = reader.CreateNavigator(); //returns an XPathNavigator based on the reader.
var root = navigator.SelectSingleNode("records");
int count;
if (!int.TryParse(root.GetAttribute("count", ""), out count) || count < 1)
return;
navigator.MoveToFirstChild();
var n = navigator.Select("record");
AddRange(n.ToList<SearchRecord>());
}
public void WriteXml(System.Xml.XmlWriter writer)
{
throw new System.NotImplementedException();
}
#endregion
}