How do I serialize SortedList

I have read the the xml serialization documentation, which says it can be used to serialize all sorts of objects including Collections.

I have tried to serialize a SortedList it seems to be succesfull but when I look at the xml it produces it fails to serialize the the elements in the list.

Is there something extra I need to do to serialize a SortedList

I have been using a work around to solve this problem but its not very neat and it involved writing code for each Collection / type combination.


Answer this question

How do I serialize SortedList

  • jhin

    Thanks

    In case anyone is reading this and wondering what my work around was:

    I created a new class which stored the information contained in the list in an 2 arrays one for keys and one for values. 

    I copied the references into the array and serialized the instance of the new class.

  • MS Guy

    It is not possible to serialize a SortedList or any other collections, implementing the IDictionary interface. This is because the IDictionary interface is about reference equality, and this can not be garantueed using serialization.

    There are several workarounds, but it seems you have already found one!

    Jan

  • Simo

    That solution is the recommended one!

    Thx for sharing,
    Jan

  • How do I serialize SortedList