当我尝试从 MyConfig.xml 反序列化时,出现内存不足异常
System.Net.IPAddress.InternalParse(String ipString, Boolean tryParse)
System.Net.IPAddress.Parse(String ipString)
MyNamespace.IPRange.ReadXml(XmlReader reader)
IPRange.cs
public class IPRange : IXmlSerializable
{
public IPRange () { }
public IPAddress StartIP { get; set; }
public IPAddress EndIP { get; set; }
public XmlSchema GetSchema()
{
throw new NotImplementedException();
}
public void ReadXml(XmlReader reader)
{
this.StartIP = IPAddress.Parse(reader.GetAttribute("StartIP"));
this.EndIP = IPAddress.Parse(reader.GetAttribute("EndIP"));
}
public void WriteXml(XmlWriter writer)
{
writer.WriteAttributeString("StartIP", this.StartIP.ToString());
writer.WriteAttributeString("EndIP", this.EndIP.ToString());
}
}
我的配置文件
public class MyConfig
{
[XmlArrayItem("IPRange")]
public List<IPRange> DMZ { get; set; }
}
MyConfig.xml
<?xml version="1.0" encoding="utf-8" ?>
<MyConfig>
<DMZ>
<IPRange StartIP="{some start ip}" EndIP="{some end ip}" />
<IPRange StartIP="{some start ip}" EndIP="{some end ip}" />
</DMZ>
</MyConfig>
我不知道我做错了什么。请帮我解决这个问题。
谢谢!