Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: Deserializing custom ArrayList type from ViewState... help..

Thread Tools

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

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

ViewState["test"] = ml;

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

"Ramzey" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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?

Reply With Quote
Posts: n/a
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.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem deserializing a custom class "'One of the serialized keys is null." Paul ASP .Net 1 10-21-2009 08:01 AM
serializing and deserializing enum type C++ 10 08-18-2007 02:41 AM
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList leal ting ASP .Net 1 02-10-2004 07:45 PM
writeObject with ArrayList of ArrayList? Kaidi Java 4 01-03-2004 08:16 PM
Iterate through ArrayList using an another ArrayList Saravanan Rathinavelu ASP .Net 3 08-19-2003 07:03 AM