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"
The Hashtable object is serializable because it implements the Serializable interface.
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.
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.
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.
Try this:
http://www.deploymentzone.com/2008/09/19/idictionarytkeytvalue-ixmlserializable-and-lambdas/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With