XMLSerializer Error with Hashtable

G

Guest

I am trying to serialize and deserialize a Class which has a Hashtable in it and I'm getting the error:

"An unhandled exception of type 'System.InvalidOperationException' occurred in system.xml.dll - Additional information: There was an error reflecting type 'HashSerializeTest.INIData'."

at runtime when I try to instantiate the XMLSerializer object with a constructor to which I pass the Class Type.

I tried it with the class just having Public string members and it worked fine. Then I added a Public Hashtable member and I started to get this error.

Help?
 
M

Manoj G [MVP]

Hi,

The XML serializer explicitly ignores serializing objects derived from
IDictionary. To work around this problem, one would need to wrap IDictionary
instances in a class that implements IXmlSerializable. For more info on
this, refer to this excellent
(http://msdn.microsoft.com/msdnmag/issues/03/06/XMLFiles/) column by Aaron
Skonnard

--
HTH,
Manoj G
[MVP , Visual Developer - Visual Basic ]
http://msmvps.com/manoj/

Alex Maghen said:
I am trying to serialize and deserialize a Class which has a Hashtable in it and I'm getting the error:

"An unhandled exception of type 'System.InvalidOperationException'
occurred in system.xml.dll - Additional information: There was an error
reflecting type 'HashSerializeTest.INIData'."
at runtime when I try to instantiate the XMLSerializer object with a
constructor to which I pass the Class Type.
I tried it with the class just having Public string members and it worked
fine. Then I added a Public Hashtable member and I started to get this
error.
 

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