Why does viewstate deserialize object as hashtable?

Discussion in 'ASP .Net' started by jw56578@gmail.com, Apr 7, 2005.

  1. Guest

    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
     
    , Apr 7, 2005
    #1
    1. Advertising

  2. Teemu Keiski Guest

    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)

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU

    <> wrote in message
    news:...
    >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
    >
     
    Teemu Keiski, Apr 7, 2005
    #2
    1. Advertising

  3. PJ Guest

    > 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.
     
    PJ, Apr 8, 2005
    #3
  4. Guest

    when i say converts it to a hashtable, i mean that the type of the
    deserialized object is Hashtable, not my original object.
     
    , Apr 9, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pico77
    Replies:
    1
    Views:
    3,317
  2. Edmond wong
    Replies:
    2
    Views:
    5,990
    Edmond wong
    Apr 29, 2005
  3. Replies:
    2
    Views:
    2,138
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,003
    Smokey Grindel
    Dec 2, 2006
  5. moonhk
    Replies:
    4
    Views:
    717
Loading...

Share This Page