Results 1 to 4 of 4

Thread: Is IDictionary serializable ?

  1. #1
    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 !!

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    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. #3
    lReegan Guest

    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. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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.

Similar Threads

  1. Serializable Singleton Implementation in Java
    By Bhardwaj in forum Software Development
    Replies: 5
    Last Post: 18-02-2010, 07:17 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,905,433.80428 seconds with 17 queries