3
votes

I was wondering if the following error,

System.Web.HttpException: 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

was caused by not serialising properties.

Any ideas?

1
Did you mark you class as Serializable? - Kamarey
Will marking classes suffice, even though I use the properties of a class when saving to session state? - Stuart
The objects are serialized using binary serialization, so it should work well. The only problem is if your objects contain other objects that are not serializable, but you can probably control that. - Rune Grimstad

1 Answers

3
votes

When you use a StateServer or SQL Server session state all objects you store in session must be serializable. For your own classes this can often be easily fixed by marking them with the [Serializable] attribute, but for classes delivered by third-parties there is no trivial fix.

If you keep running into this problem you may consider rebuilding your data on each request instead of using session state at all, but that is another discussion... :-)