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.

Serialization class that inherits from IList, ICollection with additional properties

See original GitHub issue

Hello again!

In the last few days I worked very intensive with XML serializing. For my Tests I used the default XmlSerializer and the ExtendedXmlSerialize to be able to compare the advantages and disadvantages of both. By my Tests I noticed two issues of the ExtendedXmlSerializer, which I want to tell you.

  1. when a class derives from Collections, the ExtendedXmlSerializer is not able to serialize it. Then a NullReferences Exception will be thrown.

Example class: public class ListOfTest : List<Test> { public string name { get; set; } }

The default XmlSerializer can do this, but there are also some Problems with it: -) List<T> only works when T is not an Interface -) only the List get serialized and deserialized, all other Properties don’t. (from example the property “name” would not get serialized)

  1. if a Property has the Datatype “object” the ExtendedXmlSerializer serialize it, but is not able to deserialize it. After deserializing the XML all Properties which have the Datatype “object”, would have the string “System.Object” as value.

Example: public class Test { public object testProperty { get; set; } }

TestData: Test t = new Test() { testProperty = 1234; } Test t2 = new Test() { testProperty = “name”; }

Xml-Output would look like this:

<?xml version="1.0" encoding="utf-8"?>
  <Test>
     <testProperty>
        1234
     </testProperty>
  </Test>
  <Test>
     <testProperty>
        name
     </testProperty>
  </Test>

TestData after deserialize: t.testProperty == “System.Object”; t2.testProperty == “System.Object”;

I hope this information will help you by bugfixing and by upgrading the ExtendedXmlSerializer.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
WojciechNagorskicommented, Nov 25, 2016

Properties need to have set accesory. In your case try: public Collection<ITask> Tasks { get; set; } = new Collection<ITask>(); }

0reactions
Mike-E-angelocommented, Jan 19, 2017

Yes, this should be fixed now. I just need to wire it up. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serialization class that inherits from IList, ICollection with ...
when a class derives from Collections, the ExtendedXmlSerializer is not able to serialize it. Then a NullReferences Exception will be thrown.
Read more >
c# - Serialize object when the object inherits from list
Workarround: Create a property in the class which returns the items (see here). Anyway, inherit from List<T> is rare to be a good...
Read more >
IList Interface (System.Collections)
Gets an object that can be used to synchronize access to the ICollection. (Inherited from ICollection). Methods. Add(Object). Adds an item to the...
Read more >
ICollection Interface (System.Collections)
An IList implementation is a collection of values and its members can be accessed by index, like the ArrayList class. Some collections that...
Read more >
c# - Is it a good practice to create a ClassCollection ...
Maintaining custom collection classes is a pain, and you gain little from inheriting from CollectionBase<T> that you don't get with the ...
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