Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to serialize hashtable in c#

I have implemented session state mode sqlserver and when i run my application i am facing XML serialization error of hash table . and my class looks like:

[Serializable]
    public class ProjectSetup{
    private System.Collections.Hashtable _ConfigTable;
   //and other properties here

   public System.Collections.Hashtable ConfigTable
        {
            get { return _ConfigTable; }
        }

}

Now i want to know how to serialize the hastable or if there is another alternative please let me know.

and exactly error is: "Cannot serialize member ProjectSetup.ConfigTable of type System.Collections.Hashtable, because it implements IDictionary"

like image 249
Anil Avatar asked Sep 14 '11 09:09

Anil


People also ask

Can you serialize Hashtable?

The Hashtable object is serializable because it implements the Serializable interface.

What is serialize and deserialize in C?

Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.

Can we serialize Dictionary C#?

NET objects is made easy by using the various serializer classes that it provides. But serialization of a Dictionary object is not that easy. For this, you have to create a special Dictionary class which is able to serialize itself. The serialization technique might be different in different business cases.

What is the difference between Dictionary and Hashtable in C#?

In Hashtable, you can store key/value pairs of the same type or of the different type. In Dictionary, you can store key/value pairs of same type. In Hashtable, there is no need to specify the type of the key and value. In Dictionary, you must specify the type of key and value.


1 Answers

Try this:

http://www.deploymentzone.com/2008/09/19/idictionarytkeytvalue-ixmlserializable-and-lambdas/

like image 95
Variant Avatar answered Oct 05 '22 22:10

Variant