似乎在序列化xml时发生了错误。有人知道解决方案吗?
这是一个用于获取服务器上xml数据信息的系统。 从客户端到服务器的通信过程中发生错误。 服务器系统是在visualstudio 2012上创建的。我创建了它。 使用xcode调试进行数据采集期间发生错误
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
namespace DEngine.Common.Services
{
public class WorldInfo
{
[XmlAttribute]
public int Id;
[XmlAttribute]
public string Name;
[XmlAttribute]
public string ServiceAddress;
[XmlAttribute]
public int Version;
[XmlAttribute]
public string GameDB;
}
[XmlRoot("WorldList")]
public class WorldInfoList
{
[XmlElement("World")]
public List<WorldInfo> Worlds;
public WorldInfoList()
{
Worlds = new List<WorldInfo>();
}
public static WorldInfoList FromXML(string xmlText)
{
using (StringReader strReader = new StringReader(xmlText))
{
XmlSerializer xs = new XmlSerializer(typeof(WorldInfoList));
WorldInfoList sheet = (WorldInfoList)xs.Deserialize(strReader);
return sheet;
}
}
public string ToXML()
{
XmlSerializer xs = new XmlSerializer(typeof(WorldInfoList));
XmlSerializerNamespaces xn = new XmlSerializerNamespaces();
xn.Add("", "");
using (StringWriter strWriter = new StringWriter())
{
xs.Serialize(strWriter, this, xn);
return strWriter.ToString();
}
}
}
}
错误很低
InvalidOperationException:DEngine.Common.Services.WorldInfoList 无法序列化,因为它没有默认的public 构造函数
在ActiveAnimation.Finish()[0x00000]在:0
在System.Xml.Serialization.ReflectionHelper.CheckSerializableType (System.Type类型,布尔型allowPrivateConstructors)在[0x00000]中 :0
在System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping中的(System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute根,System.String defaultNamespace)[0x00000]在:0
作为InvalidOperationException重新抛出:出现错误,反映 键入“ DEngine.Common.Services.WorldInfoList”。