Welcome to MSDN Blogs Sign in | Join | Help

Santhosh Pillai

Globalization challenges... one at a time.

Syndication

News

The posting provided here is "AS IS" with no warranties, and confers no rights. You assume all risk for your use. ©2004-2007 Microsoft Corporation. All rights reserved.
Error: The type is not supported because it implements IDictionary.

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?

Published Tuesday, February 24, 2004 2:57 PM by sanpil

Comments

# re: Error: The type <type name> is not supported because it implements IDictionary. @ Tuesday, February 24, 2004 3:07 PM

I will try and get a small repro project as the real problem is in live code.

Ferris Beuller

# re: Error: The type <type name> is not supported because it implements IDictionary. @ Tuesday, February 24, 2004 3:08 PM

Are you using Framework 1.0 or 1.1?

Santhosh Pillai

# re: Error: The type <type name> is not supported because it implements IDictionary. @ Tuesday, February 24, 2004 3:09 PM

Until then I would isolate where you are throwing those exceptions in the actual serializer to see what conditions would causé that because I am obviously hitting them.

I would also check for comments like

// This should not happen
:D first place it jumps :D

Ferris Beuller

# re: Error: The type <type name> is not supported because it implements IDictionary. @ Tuesday, February 24, 2004 3:09 PM

Visual Studio .NET 2003 which I would imagine is 1.1, right?

Once I have a repro scenario on that IDE I will try it on my home 2002 edition.

Ferris Beuller

# re: Error: The type <type name> is not supported because it implements IDictionary. @ Tuesday, February 24, 2004 3:11 PM

Visual Studio .NET 2003 which I would imagine is 1.1, right?

Once I have a repro scenario on that IDE I will try it on my home 2002 edition.

Ferris Beuller

# re: Error: The type <type name> is not supported because it implements IDictionary. @ Tuesday, February 24, 2004 4:40 PM

I think he's talking about XML Serialization, not binary.

Julien Ellie

# re: Error: The type <type name> is not supported because it implements IDictionary. @ Tuesday, February 24, 2004 5:56 PM

Yes - I think he is talking about XML serialization too. IIRR I've been able to serialize plenty of things under framework 1.0 and 1.1.

JosephCooney

# re: Error: The type <type name> is not supported because it implements IDictionary. @ Tuesday, February 24, 2004 6:06 PM

Yes I was referring to XmlSerializer.

Ferris Beuller

# re: Error: The type <type name> is not supported because it implements IDictionary. @ Tuesday, February 24, 2004 6:06 PM

Whats this newfangled BinaryFormatter Serializer thang, never seen it before.
hmm..

Ferris Beuller

# re: Error: The type <type name> is not supported because it implements IDictionary. @ Tuesday, February 24, 2004 6:27 PM

Here, try this...

http://msdn.microsoft.com/msdnmag/issues/03/06/XMLFiles/default.aspx

(2/3 of the way down)

You can serialize IDictionary but you need to tell the serializer what the format of the XML should be by implementing IXmlSerializable.

Johnny Hall

# re: Error: The type <type name> is not supported because it implements IDictionary. @ Tuesday, February 24, 2004 5:03 PM

But why do they disable serialization on IDictionary based collections?

Ferris Beuller

# re: Error: The type <type name> is not supported because it implements IDictionary. @ Wednesday, February 25, 2004 3:10 AM

I believe it is because the XmlSerializer has no way to know what format to serialize a dictionary as, because there is no equivalent type in XML Schema.

The only way to do it would have been to "hard-code" an XML format into IDictionary, or into the XmlSerializer code itself.

And you have to remember that XmlSerializer was (I believe) added to the framework late on, and that it started out as someone's personal project. Though don't quote me on that, I could be wrong.

Johnny Hall

Anonymous comments are disabled
Page view tracker