0

On my development machine I do not get an error, I deployed to another machine with remote debugged and it throws a StackOverflowException error when Deserializing the xml to a class object. I am pretty sure the xml is incorrect and there is recursion going on. Please can somebody help me identify it as I have tried and failed.

One more question is why does the exception not occur on my development machine, could it be suppressed in the IDE settings? How do I duplicate the exception I am getting on the remote machine to my develpoment machine.

XML Code

[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 File that is created

    <?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>

many thanks,

Paul.

user2006049
  • 9
  • 1
  • 4
  • could you send an xml output that you got an error? if you are reading an xml file via xml,encoding may be a problem. – go.. Nov 30 '16 at 10:13
  • Well, as might be expected, I cannot reproduce it. See https://dotnetfiddle.net/iSciy7. Could you have an obsolete sgen-generated `.XmlSerializers.dll` left on the remote machine? See https://msdn.microsoft.com/en-us/library/bk3w6240(v=vs.110).aspx or [Generating an Xml Serialization assembly as part of my build](https://stackoverflow.com/questions/134224/generating-an-xml-serialization-assembly-as-part-of-my-build). – dbc Nov 30 '16 at 10:21
  • The XmlSerializer class uses this assembly C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.dll, i have checked on the remote machine and it is there. – user2006049 Nov 30 '16 at 12:16
  • The error i get just says StackOverflowException occurred in mscorlib.dll – user2006049 Nov 30 '16 at 12:18

0 Answers0