<分区>
我在反序列化 XML 文档时遇到问题。它给了我:
There is an error in XML document (1, 23). ---> System.InvalidOperationException: was not expected.
这是我的 XML:
<?xml version="1.0" ?>
<car>
<msg>asdfgg</msg>
<userGUID>234234</userGUID>
<event>vfrewvwev</event>
</car>
这是我生成的类:
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xsd2Code", "3.4.0.37595")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class car: System.ComponentModel.INotifyPropertyChanged {...
这是我使用的反序列化方法:
MyApp ma = MyApp.Deserialize(strXml);
public static MyApp Deserialize(string xml)
{
System.IO.StringReader stringReader = null;
try
{
stringReader = new System.IO.StringReader(xml);
return ((MyApp)(Serializer.Deserialize(System.Xml.XmlReader.Create(stringReader))));
}
finally
{
if ((stringReader != null))
{
stringReader.Dispose();
}
}
}