C# – Unable to serialize the session state

asp.netciisiis-6

We have reasonably large scale application and recently experiencing issues with random logouts. Upon investigation we've found app pool is recycling after physical memory limit of (1GB)is reached. I m now trying to save session state in out of process as below

<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" cookieless="false" timeout="20"/>

After changing the session state mode to "StateServer" and running the asp.net state service on server. I m getting the following error message

"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."

Apparently i have to mark session related objects with [Serializable] attribute but the application is quite big. Is there a way around this issue?

thanks

Best Answer

Is there a way around this issue?

No, you have to analyze all the objects that are participating in the object graph that you are storing into the session and decorate them with the [Serializable] attribute.

The alternative's not gonna like you: write a custom session state provider where you will have control over the serialization of your session state objects but that's usually an overkill.

Related Topic