XMl反序列化StackOverflowException
本文关键字:StackOverflowException 反序列化 XMl | 更新日期: 2023-09-27 18:15:23
我试图从一个已经保存的。xml文件反序列化类。问题是,只要我使用get{...} set{...};
的代码抛出StackOverflow异常。我要用这段代码创建一个无限循环吗?因为我无法找到一个有停止点的循环
类:
[Serializable]
public class AddOn
{
[System.Xml.Serialization.XmlElement("Name")]
public string Name { set; get; }
[XmlIgnore]
public ProcessStartInfo Info {
set { Info = value; }
get {
Info.Arguments = args;
Info.Arguments = Path;
return Info;
}
}
[System.Xml.Serialization.XmlElement("Arguments")]
public string args { set; get; }
[System.Xml.Serialization.XmlElement("Path")]
public string Path { set; get; }
[XmlIgnore]
public List<Process> ChildProcess = new List<Process>();
public AddOn(string Name, ProcessStartInfo Info)
{
this.Name = Name;
this.Info = Info;
args = Info.Arguments;
Path= Info.FileName;
}
public AddOn() { }
}
的[XmlIgnore]
public ProcessStartInfo Info {
set { Info = value; }
get {
Info.Arguments = args;
Info.Arguments = Path;
return Info;
}
}
get{...}
函数抛出StackOverflowException.
我忽略了ProcessStartInfo,因为我无法在第一个地方序列化这个类型,因此创建了两个字符串args和Path。
应该返回反序列化的插件列表的代码:
XmlSerializer serializer = new XmlSerializer(typeof(ObservableCollection<AddOn>));
StreamReader reader = new StreamReader(path);
var addons = (ObservableCollection<AddOn>)serializer.Deserialize(reader);
reader.Close();
return addons;
this call
public ProcessStartInfo **Info** {
**set { Info = value; }**
get {
Info.Arguments = args;
Info.Arguments = Path;
return Info;
}
}
调用自身导致溢出