Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 27-07-2009
Member
 
Join Date: Jun 2009
Posts: 41
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 !!
Reply With Quote
  #2  
Old 27-07-2009
Member
 
Join Date: May 2008
Posts: 2,383
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.
Reply With Quote
  #3  
Old 27-07-2009
lReegan
 
Posts: n/a
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.
Reply With Quote
  #4  
Old 27-07-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Is IDictionary serializable ?"
Thread Thread Starter Forum Replies Last Post
Serializable Singleton Implementation in Java Bhardwaj Software Development 5 18-02-2010 07:17 PM


All times are GMT +5.5. The time now is 09:18 PM.