我试图在C#中反序列化一个基本的xml文件。这是反序列化代码:
using (var reader = new StreamReader("Plugins/LSPDFR/LSPSAddonCallouts.xml"))
{
XmlSerializer deserializer = new XmlSerializer(typeof(List<Custom.CustomMission>),
new XmlRootAttribute("CustomMissions"));
customMissions.AddRange((List<Custom.CustomMission>)deserializer.Deserialize(reader));
}
但运行代码时出现此错误:
Errore nel documento XML (9, 4). in System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
[11/04/2017 10:56:51.346] in System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
[11/04/2017 10:56:51.347] System.FormatException: Formato della stringa di input non corretto.
[11/04/2017 10:56:51.347] in System.Number.ParseSingle(String value, NumberStyles options, NumberFormatInfo numfmt)
[11/04/2017 10:56:51.347] in System.Xml.XmlConvert.ToSingle(String s)
[11/04/2017 10:56:51.348] in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderList1.Read2_CustomMission(Boolean isNullable, Boolean checkType)
[11/04/2017 10:56:51.348] in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderList1.Read3_CustomMissions()
导致我的xml文件出现问题的行是这一行:
<startposprotaY>-726.2017f</startposprotaY>
在此行之前还有其他浮点数被反序列化而没有任何问题,但是这个不会。与其他浮点数的唯一区别是,这是xml文件的唯一负浮点数,其他浮点数是正数。