The XmlSerializer will throw the following NotSupportedException when you
pass a Type that implements IDictionary to the constructor:

NotSupportedException
The type System.Collections.Hashtable is not supported because it implements
IDictionary.
at System.Xml.Serialization.TypeScope.GetCollectionElementType(Type type)
at System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, Boolean
canBePrimitive, Boolean throwOnNoDefaultCtor, MemberInfo memberInfo)
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo
source, Boolean throwOnDefaultCtor)
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type)
at System.Xml.Serialization.ModelScope.GetTypeModel(Type type)
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type
type, XmlRootAttribute root, String defaultNamespace)

Looks like it specifically looks for IDictionary and rejects anything that
implements it. It seems that you should be able to iterate over the
collection and serialize keys and values, but maybe there is something in
the implementation of the Hashtable that prevents that.

HTH,
Christoph Schittko
Software Architect
Mshow - a division of InterCall

----- Original Message -----
From: "Ian Griffiths" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, June 05, 2002 10:02 AM
Subject: Re: [DOTNET] Hashtable XML Serialization


> But IDictionary derives from ICollection!  So by definition, anything that
> implements IDictionary also implements ICollection.
>
> Or are you saying that it looks specifically for IDictionary and avoids
> serializing anything that implements it?  (I.e. that it will only
serialize
> collections that implement ICollection but not IDictionary?)
>
>
> --
> Ian Griffiths
> DevelopMentor
>
> ----- Original Message -----
> From: "Christoph" <[EMAIL PROTECTED]>
>
>
> > The XmlSerializer will not touch anything that implements IDictionary,
it
> > only serializes collections implementing ICollection or IList. Thus you
> > can't just derive a class because the derived class implements
> IDictionary.
> >
> > You have to write a wrapper class with some public properties to access
> the
> > contents of the Hashtable for the XmlSerializer to handle it.
> >
> > Let me know if you need more info.
> >
> > ----- Original Message -----
> > From: "Rolls, Robert" <[EMAIL PROTECTED]>
> > >
> >
>
http://discuss.develop.com/archives/wa.exe?A2=ind0201C&L=DOTNET&P=R1973&m=39
> > > 477
> > >
> > > Ivan mentioned writing a wrapper class and adding the Add method? I'm
> not
> > > exactly sure what I need to do? anybody like to explain in simple
> English.
> > > Could you not derive from Hastable and add an interface that would
sort
> > > the problem out?
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to