question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deserialization using ".WithUnknownContent().Continue()" still silently aborts on unknown content.

See original GitHub issue

Some code to repro:

    public class Test
    {
        public int Value1 { get; set; }
        //public Item Item1 { get; set; }
        public int Value2 { get; set; }
        //public List<int> Items2 { get; set; }
        public int Value3 { get; set; }
        //public List<Item> Items3 { get; set; }
        public int Value4 { get; set; }
    }

    public class Item
    {
        public int Value { get; set; }
    }

    class Program
    {
        static void Main()
        {
            const string inputXml =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<Test xmlns=""clr-namespace:ExsDeserializationIssue;assembly=ExsDeserializationIssue"">
  <Value1>11</Value1>
  <Item1>
    <Value>1</Value>
  </Item1>
  <Value2>22</Value2>
  <Items2>
    <Capacity>4</Capacity>
    <int xmlns=""https://extendedxmlserializer.github.io/system"">1</int>
    <int xmlns=""https://extendedxmlserializer.github.io/system"">2</int>
    <int xmlns=""https://extendedxmlserializer.github.io/system"">3</int>
  </Items2>
  <Value3>33</Value3>
  <Items3>
    <Capacity>4</Capacity>
    <Item>
      <Value>1</Value>
    </Item>
    <Item>
      <Value>2</Value>
    </Item>
    <Item>
      <Value>3</Value>
    </Item>
  </Items3>
  <Value4>44</Value4>
</Test>";

            var s = new ConfigurationContainer()
                .WithUnknownContent()
                .Continue()
                //.Call(_ => Console.WriteLine("Unknown content: " + _.Name))
                .Create();

            var output = s.Deserialize<Test>(inputXml);
            Console.WriteLine(output.Value1); // 11
            Console.WriteLine(output.Value2); // 0 but should be 22
            Console.WriteLine(output.Value3); // 0 but should be 33
            Console.WriteLine(output.Value4); // 0 but should be 44

            // --- Below is the code that generates the input XML when the "Items" lists are uncommented.

            //var t = new Test
            //{
            //    Value1 = 11,
            //    Value2 = 22,
            //    Value3 = 33,
            //    Value4 = 44,
            //    Item1 = new() { Value = 1 },
            //    Items2 = new()
            //    {
            //        1,
            //        2,
            //        3,
            //    },
            //    Items3 = new()
            //    {
            //        new() { Value = 1 },
            //        new() { Value = 2 },
            //        new() { Value = 3 },
            //    }
            //};

            //var outputXml = s.Serialize(new XmlWriterSettings() { Indent = true }, t);
            //Console.WriteLine(outputXml);
        }
    }

Also, when Call is used instead of Continue, the delegate is only invoked for “Item1”.

For what it’s worth, I think I can see Continue partially working when deserializing my real XML, which is much larger. It makes it past a few elements for which there’s no matching property, then it inexplicably fails (i.e. silently aborts) when it reaches a certain unknown element. I’ve tried to figure out a pattern to what finally triggers the silent failure, but I can’t get quite the same behavior in simpler setups, including the repro here. Regardless, this repro does seem to show Continue misbehaving. Or am I missing something?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rummelsworthcommented, May 25, 2021

@Mike-E-angelo Sorry for not following up earlier. I hadn’t gotten around to trying it at that time due to a weirdness with nuget and installing the preview build, then I ended up figuring out what I was doing wrong in my original use of XmlSerializer (which had prompted me to investigate this package). After plunging ahead, I forgot to come back and try this out to confirm the fix on my end. Anyway, I appreciate your super-quick response and resolution on this issue! Truly impressive. Thanks.

0reactions
Mike-E-angelocommented, May 26, 2021

No worries @rummelsworth! I am glad it is working for you and we got this squared away. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Question: Deserializing with unknown content · Issue #571
I tried the above configurationContainers to deserialize an xml file without unknown content but noticed the deserialization no longer works ...
Read more >
Deserialisation terminates silently at element for property marked ...
I am finding that ExtendedXmlSerializer.Deserialize() stops processing the document if it encounters an element that corresponds to a property that is marked ...
Read more >
W3C Technical Architecture Group -- 09 Dec 2008
stuart: re agenda: I propose an error handling discussion with Raman at 15:30 today. ... < timbl > This is very analogous to...
Read more >
Realm Management Monitor specification
Clarify behavior of VmidIsValid() function (FENIMORE-630) ... This Licence shall remain in force until terminated by Licensee or by Arm.
Read more >
[gtk+] (46001 commits) Non-fast-forward update to branch ...
Use construct-time properties with g_object_new() instead o ef0b246. ... Simply skip APP1 markers with unknown content in JPEG files b9c638b ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found