Friday, May 27, 2005

 

Serializable

Problem

I was trying to add a custom collection of business entities/objects to the Session using the following code:

Session["MatchingFiles"] = files;

When I opened the aspx page that called the above code I received the following error message:

Exception Information: Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode. (System.Web.HttpException)


OK, no problem. I will just add [Serializable] to the top of both the custom collection and business object class declarations. After doing this, I refreshed the aspx page and received the same error message.

Solution

It took some doing, but I finally realized that both of these classes inherit from base classes. Neither of these base classes were marked serializable. Once I added [Serializable] to the base classes, the custom collection was able to be stored in Session state.

Comments: Post a Comment

Links to this post:

Create a Link



<< Home
Content copyright ©2003-2006 Tod Birdsall