Why does viewstate deserialize object as hashtable?

J

jw56578

I have an object that inherits from hashtable and is serializable to be
stored in the viewstate, but when I retrieve it from viewstate, it is
converted into a hashtable, why won't it stay as the original object?
thanks
 
T

Teemu Keiski

Hi,

Your question is confusing. Define what means "it is converted into
HashTable" (post the code). Do you mean that you are handed with Hashtable
instance even though it is derived from HT (did you do casting to the
derived type after getting object from the Viewstate and got exceptions)?

I'd like to see the sample code. And you did specify serialization by
appending Serializable attribute or did you reimplement ISerializable
inetrface implemented by HT?

One reason I'm thinking for this, is that Hashtable implements ISerializable
interface, and I suppose it could be possible that its default
implementation is used (which would instantiate Hashtable), unless you
redeclare it. (though it sounds weird)
 
P

PJ

One reason I'm thinking for this, is that Hashtable implements
ISerializable
interface, and I suppose it could be possible that its default
implementation is used (which would instantiate Hashtable), unless you
redeclare it. (though it sounds weird)

That's exactly right. Asp.net calls the ISerializable methods and since you
do not override the appropriate methods in your derived object, it uses the
hashtables implementation...which, of course, only serializes and
deserializes itself.
 
J

jw56578

when i say converts it to a hashtable, i mean that the type of the
deserialized object is Hashtable, not my original object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top