Ferris Beuller asked me in response to my previous post:
Why can the serializer not serialize types that implement IDictionary? SortedList in types cannot be serialized, you get an InvalidOperationException with the innerexception of {"The type System.Collections.SortedList is not supported because it implements IDictionary."}
The serializer should be able to serialize any type as long as it is marked serializable. SortedList is marked serializable. So, you should not be getting this error. I was able to run the following test without getting any errors.
using System;using System.Collections;using System.Runtime.Serialization.Formatters.Binary;using System.IO;
namespace SerializeDict{ public class Test { public static void Main() { MemoryStream stream = new MemoryStream(); BinaryFormatter bf = new BinaryFormatter(); SortedList list = new SortedList(); list.Add(10, 100); list.Add(100, 1000); bf.Serialize(stream, list); stream.Position = 0; bf = new BinaryFormatter(); list = (SortedList)bf.Deserialize(stream); Console.WriteLine(list[100]); } }}
Can you share a reproducible sample with me where you get the error?