|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
Is IDictionary serializable ? Hello, I'm working with a Asp.net application,so in which a class GfProjects.I used in a Profile implements IDictionary. The class is marked as serializable and the profiles saved and read successfully. I have created an Asp.Net web service which gets this profile field,however when I test it on IE which bring up errors like "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]], I doubt since it is implementing IDictionary am getting this crass things.guys please help me in this regard.. Any help would be really appreciable !! |
#2
| |||
| |||
Re: Is IDictionary serializable ? I found a convenient way with a .NET class called KeyedCollection. KeyedCollection derives from the iList interface instead of iDictionary, and is therefore serializable, but also allows you to specify a key. This class is an abstract type, so you must derive your own custom class, but as we?ll see in a second, that?s a snap.binary (or possibly soap) which works and xml serialization which doesn't. XML Serialization is what's used by the web service. |
#3
| |||
| |||
Re: Is IDictionary serializable ? My guess is you are actually using XML serialization through XmlSerializer.it does not support IDictionary for some odd reasons but you can possibly write your own class that implements IDictionary but is serializable regardless if you implement IXmlSerializable explicitly.But if you migrate your web service to WCF instead, you won't face this issue, it uses DataContractSerializer rather than XmlSerializer. |
#4
| |||
| |||
Re: Is IDictionary serializable ? Hi there, Override XmlSerialization by creating the type implement the System.Xml.Serialization.IXmlSerializable class.Implement how you need the object to be serialized in XML in the WriteXml method, and how you could recreate the object from an xml string in the ReadXml method. When XmlSerializer attempts to serialize a type and finds that it implements IXmlSerializable, the serializer would simply pass control to the ReadXml or WriteXml methods. same time KeyedCollection derives from the iList interface instead of iDictionary, and is therefore serializable.So if you need a keyed list and your objects include unique values, you can use KeyedCollection and get the benefits of serialization as well. |
![]() |
|
Tags: gfprojects, idictionary, serializable |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Serializable Singleton Implementation in Java | Bhardwaj | Software Development | 5 | 18-02-2010 07:17 PM |