StackOverflowException反序列化为对象递归错误

时间:2016-11-30 10:07:09

标签: c# xml object serialization stack-overflow

在我的开发机器上,我没有收到错误,我部署到另一台远程调试的机器,并在将xml反序列化为类对象时抛出了StackOverflowException错误。我很确定xml是不正确的,并且正在进行递归。请有人帮我识别它,因为我尝试过并且失败了。

还有一个问题是为什么我的开发机器上不会发生异常,是否可以在IDE设置中将其抑制?如何将我在远程计算机上获得的异常复制到我的开发机器上。

XML代码

[XmlRoot("Symbols")]
public class Symbols
{
    [XmlElement("Metals")]
    public Metal MetalGroup { get; set; }

    [XmlElement("Forex")]
    public Forex ForexGroup { get; set; }

    [XmlElement("Indices")]
    public Indices IndicesGroup { get; set; }

    [XmlElement("Other")]
    public Other OtherGroup { get; set; }

    public class Metal
    {
        [XmlAttribute("id")]
        public string Id { get; set; }

        [XmlAttribute("name")]
        public string Name { get; set; }

        [XmlElement("Symbol")]
        public List<MetalSymbol> SymbolList { get; set; }

        public class MetalSymbol
        {
            [XmlAttribute("id")]
            public string Id { get; set; }

            [XmlAttribute("name")]
            public string Name { get; set; }
        }
    }

    public class Forex
    {
        [XmlAttribute("id")]
        public string Id { get; set; }

        [XmlAttribute("name")]
        public string Name { get; set; }

        [XmlElement("Symbol")]
        public List<ForexSymbol> SymbolList { get; set; }

        public class ForexSymbol
        {
            [XmlAttribute("id")]
            public string Id { get; set; }

            [XmlAttribute("name")]
            public string Name { get; set; }
        }
    }

    public class Indices
    {
        [XmlAttribute("id")]
        public string Id { get; set; }

        [XmlAttribute("name")]
        public string Name { get; set; }

        [XmlElement("Symbol")]
        public List<IndicesSymbol> SymbolList { get; set; }

        public class IndicesSymbol
        {
            [XmlAttribute("id")]
            public string Id { get; set; }

            [XmlAttribute("name")]
            public string Name { get; set; }
        }
    }

    public class Other
    {
        [XmlAttribute("id")]
        public string Id { get; set; }

        [XmlAttribute("name")]
        public string Name { get; set; }

        [XmlElement("Symbol")]
        public List<OtherSymbol> SymbolList { get; set; }

        public class OtherSymbol
        {
            [XmlAttribute("id")]
            public string Id { get; set; }

            [XmlAttribute("name")]
            public string Name { get; set; }
        }
    }
}

**Client Code**

XmlSerializer serializer = new XmlSerializer(typeof(Symbols));

创建的Xml文件

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Symbols>
  <Forex name="Forex">
    <Symbol name="EURUSD" />
    <Symbol name="GBPUSD" />
    <Symbol name="EURJPY" />
    <Symbol name="USDJPY" />
    <Symbol name="AUDUSD" />
    <Symbol name="USDCHF" />
    <Symbol name="GBPJPY" />
    <Symbol name="USDCAD" />
    <Symbol name="EURGBP" />
    <Symbol name="- add symbol code -" />
  </Forex>
  <Metals name="Metals">
    <Symbol name="XAUUSD" />
    <Symbol name="XAGUSD" />
    <Symbol name="XAUEUR" />
    <Symbol name="XAGEUR" />
    <Symbol name="- add symbol code -" />
  </Metals>
  <Indices name="Indices">
    <Symbol name="#GerTech30" />
    <Symbol name="#GerTech30" />
    <Symbol name="#Holland25" />
    <Symbol name="- add symbol code -" />
  </Indices>
  <Other name="Other">
    <Symbol name="#Easyjet" />
    <Symbol name="- add symbol code -" />
  </Other>
</Symbols>
非常感谢,

保罗。

0 个答案:

没有答案
相关问题