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.

`WithUnknownContent` Does Not Support List Members

See original GitHub issue

Hello and thank you very much for the EXS library. I would like to ask about the way how unknown elements are deserialized into array/list items. Please consider following example. Currently extended serializer creates an instance of animal per each inner element of Animals node even for cases that element name is not Animal. Is there a way to configure EXS not do so and skip these unknown elements? This behavior differs from standard XmlSerializer which does not deserialize unknown child elements. Any help would be very appreciated.

[Test]
public void ShouldIgnoreUnknownXmlArrayItems()
{
    var input = "<Zoo><Animals><Animal/><Animal/><Human/></Animals></Zoo>";

    var serializer = new ConfigurationContainer()
        .Type<Zoo>()
        .Name("Zoo")
        .EnableImplicitTyping(typeof(Zoo))
        .Create();

    var contentStream = new MemoryStream(Encoding.UTF8.GetBytes(input));
    var reader = XmlReader.Create(contentStream));
    var deserialized = (Zoo) serializer.Deserialize(reader);

    Assert.That(deserialized.Animals.Count, Is.EqualTo(2));
}

public class Zoo
{
    public List<Animal> Animals { get; set; }
}

public class Animal
{
}

I was trying to play around with WithUnknownContent method and put breakpoint into Call lambda as described in #256 . However the breakpoint was never hit by debugger.

.EnableReaderContext()
.WithUnknownContent().Call(reader =>
{
    // debugger never reach this code
    var content = reader.Content();
})

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Mike-E-angelocommented, Dec 8, 2020

This has been deployed to NuGet and deployed here: https://www.nuget.org/packages/ExtendedXmlSerializer/

Thanks again for your patience and collaboration with this issue. It is very much appreciated! I am glad we were able to track this down and it wouldn’t have been possible without your sleuthing.

If you find any additional issues with this please do let me know and I will see if they can be addressed. Closing for now.

<div>ExtendedXmlSerializer 3.5.0</div><div>An extensible Xml Serializer for .NET that builds on the functionality of the classic XmlSerializer with a powerful and robust extension model.</div>
1reaction
onetocnycommented, Dec 3, 2020

Thank you Mike. I am glad to see that I was almost there. Yesterday I was just playing with that UnknownContentHandlingExtension.Services class but I did not know about the IClassification that does the magic. And regarding the design of code - to be honest, show me a good developer who never wanted to delete whole solution and start all over.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Collective HUs and HUs with Unknown Content in Inbound ...
Process Steps: · An inbound delivery with several physical HUs, but there is no information about which product items are packed into which...
Read more >
Unknown file type MIME?
Do I have to specify a MIME type if the uploaded file has no extension? In other words is there a default general...
Read more >
Add application/json support on IIS 7
I have several WCF services that i want to host on an IIS 7 machine. My clients will POST data to these services...
Read more >
Properly configuring server MIME types - MDN Web Docs
If a web server or application reports an incorrect MIME type for content (including a "default type" for unknown content), a web browser...
Read more >
ASAM MDF - Wiki
The introduction of distributed data blocks in ASAM MDF 4.0 was essential to support a practicable implementation of sorted writing: Instead of writing...
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