Serialization issue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I was trying to serialize a type that has a SortedList in it and I get the
following innerexception.

{"The type System.Collections.SortedList is not supported because it
implements IDictionary." }

Why can this not be serialized, this means I have to start packing my type
into another momento type for serialization. Time wasted.
 
If you are following the business object model paradigm, you should probably use custom collections anyway. They are easy to implement and they give you much more control over your sorting etc

Just inherit from CollectionBase, and implement IComparable on your individual item. IComparable only has one method you need to implement, compareTo, which can just be a one liner: return(obj1-obj2).
 
I just need a quick way to serialize it if its not dooable with
XmlSerializer, I will probably pull them out of the collection and pack them
into a normal list, then unpack them into a sorted list again.


Clayton Gulick said:
If you are following the business object model paradigm, you should
probably use custom collections anyway. They are easy to implement and they
give you much more control over your sorting etc.
Just inherit from CollectionBase, and implement IComparable on your
individual item. IComparable only has one method you need to implement,
compareTo, which can just be a one liner: return(obj1-obj2).
 
Hi,

Thank you for posting in the community!

Based on my understanding, you want to serialize a class which takes
SortedList in it, but an exception generates.

===========================================
You use Binary Serialization or XmlSerialization?
I think you may use the XmlSerialization. There is an already know issue
about Xml Serialize class that implement IDictionary(Such as HashTable)
This is because XmlSerializer does not support serialization of IDictionary
in this .Net version.

To workaround this issue, you may just use SoapFormatter to serialize your
class, do like this:

using System;
using System.Collections;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Soap;

public class MyClass {
public static void Main() {
SoapFormatter sf = new SoapFormatter();

Hashtable objHashtable = new Hashtable();
objHashtable.Add(1, "Paolo");
objHashtable.Add(2, "Katty");
objHashtable.Add(3, "Marco");


Stream s1 = File.Create("ht.soap");
sf.Serialize(Console.Out, objHashtable);

s1.Close();
}
}

If you still have concern on the un-support of this XmlSerialize function,
you can provide your suggestion to:
http://register.microsoft.com/mswish/suggestion.asp
or mail to: (e-mail address removed)

=====================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi,

Thanks for your feedback.

I think it may be supported in furture version. But I can not confirm for
you now. So I suggest you feedback your wish to that suggestion link.

Then microsoft will consider your suggestion.

Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
The SortedList is part of a complex class that I needed to serialize along
that is also serialized with other types into an "export / import" XML
package for transfering data across systems so I am not trying to find a
workaround (if that means repacking the data into a new type that can be
serialised then so be it, a momento type of ArrayList for hte sorted list
contents will probably do).
 
I submitted a feedback under the product Visual Studio but there is no
specific listing for the .NET libraries which doesn't feel good. Makes me
feel there is nobody dealing specifically with the actual libraries for
developent on that feedback form.
 
Hi,

Oh, I see your concern, I will help you to forward your suggestion to our
product team.

If you have any further concern, please feel free to post.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top