Re: Deserializing custom ArrayList type from ViewState... help..

Discussion in 'ASP .Net' started by PJ, Jun 25, 2003.

  1. PJ

    PJ Guest

    > // this doesn't work
    > EmployeeList ml (EmployeeList)ViewState["test"];


    try:
    ViewState["test"] = ml;

    make sure the classes that are stored in the arraylist are attributed w/
    [Serializable] as well.


    "Ramzey" <> wrote in message
    news:...
    > I have a custom class that uses ArrayList as its base type. I've
    > tagged on the [Serializable] attribute to the class definition and I
    > can add the class to ViewState or Session on my ASP.NET page.
    >
    > // this works fine
    > EmployeeList myemp = new EmployeeList();
    > myemp.Add(emp1);
    > myemp.Add(emp2);
    > ...
    >
    > ViewState["test"] = myemp;
    >
    >
    > The problem comes when trying to cast my custom collection out of
    > ViewState. The failure occurs when I try to cast it out, however if I
    > try to cast back to ArrayList that works fine.
    >
    > e.g.
    >
    > // this works
    > ArrayList ml = (ArrayList)ViewState["test"];
    >
    > // this doesn't work
    > EmployeeList ml (EmployeeList)ViewState["test"];
    >
    > What do I need to add inside my custom collection object to make it so
    > that ViewState can cast back to it when deserialization occurs?
     
    PJ, Jun 25, 2003
    #1
    1. Advertising

  2. PJ

    Ramzey Guest

    All classes down the chain are tagged [Serializable]. If this were a
    problem I wouldn't be able to cast back to an ArrayList type either,
    but since I can it seems I have something missing from my EmployeeList
    class. It seems during the deserialization process the deserializer
    wants to cast it back to an ArrayList type. I assume deserializer
    method call from ViewState is getting a response back from my custom
    object that it should be cast to an ArrayList type.. The Microsoft
    documention makes sense, but it doesn't address this.
     
    Ramzey, Jun 25, 2003
    #2
    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. leal ting
    Replies:
    1
    Views:
    526
    Bryan Donaldson
    Feb 10, 2004
  2. ce
    Replies:
    2
    Views:
    4,065
  3. Paul
    Replies:
    1
    Views:
    1,453
    sctosh
    Oct 21, 2009
  4. Mingus Tsai
    Replies:
    4
    Views:
    351
    Mingus Tsai
    Oct 14, 2005
  5. Replies:
    10
    Views:
    755
    Ian Collins
    Aug 18, 2007
Loading...

Share This Page