Sql – Is it necessary to serialise properties when using sqlserver session state for .net 3.5 framework and IIS 7.0

asp.netnetsql server

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?

Best Answer

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... :-)

Related Topic