Is IDictionary serializable ?

O

Oriane

Hi there,

in an Asp.net application, a class GfProjects I used in a Profile implements
IDictionary. The class is marked as [Serializable] and the profiles appear
to be saved and read succesfully. However, I've build an Asp.Net web service
which gets this profile field, and when I test it on IE, I get the following
message:

"Cannot serialise member XXX.GfProjects of type
System.Collections.Generic.Dictionary`2[[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[Gilif.Auth.GilifProject, Gilif.Auth,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=4df35566e5ba3853]], since
it is implementing IDictionary."

So what ?

Oriane
 
M

mwilson

Hi there,

in an Asp.net application, a class GfProjects I used in a Profile implements
IDictionary. The class is marked as [Serializable] and the profiles appear
to be saved and read succesfully. However, I've build an Asp.Net web service...

You're serializing using two different serialization methods here:
binary (or possibly soap) which works and xml serialization which
doesn't. XML Serialization is what's used by the web service.

This author seems to have a workaround you can use:

http://msmvps.com/blogs/rakeshrajan/archive/2006/01/15/81105.aspx
 
P

Pavel Minaev

in an Asp.net application, a class GfProjects I used in a Profile implements
IDictionary. The class is marked as [Serializable] and the profiles appear
to be saved and read succesfully. However, I've build an Asp.Net web service
which gets this profile field, and when I test it on IE, I get the following
message:

"Cannot serialise member XXX.GfProjects of type
System.Collections.Generic.Dictionary`2[[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[Gilif.Auth.GilifProject, Gilif.Auth,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=4df35566e5ba3853]], since
it is implementing IDictionary."

So what ?

In the second case, you're actually using XML serialization via
XmlSerializer. That one, indeed, does not support IDictionary for some
obscure reasons (though you can write your own class that implements
IDictionary but is serializable regardless - if you implement
IXmlSerializable explicitly).

On a side note, if you migrate your web service to WCF instead, you
won't have this problem - it uses DataContractSerializer instead of
XmlSerializer, and the former fully supports IDictionary,
 
O

Oriane

Hi Pavel,
<"Pavel Minaev" <[email protected]> a écrit dans le message de
<In the second case, you're actually using XML serialization via
<XmlSerializer. That one, indeed, does not support IDictionary for some
<obscure reasons (though you can write your own class that implements
<IDictionary but is serializable regardless - if you implement
<IXmlSerializable explicitly).
Ok then...

<On a side note, if you migrate your web service to WCF instead, you
<won't have this problem - it uses DataContractSerializer instead of
<XmlSerializer, and the former fully supports IDictionary,
Yes it seems to be the best choice...

Thanks to you (and Sloan and mWilson)

Oriane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top