I have an .Net 3x application using default WCF serialization and recently setup application to use SQL Server Session state and am not being able to store those objects in session state with sql server, only in proc session state.
Getting errors on various classes stating:
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.
I assumed that the default serialization of wcf would be sufficient but apparently not. A开发者_运维问答ny ideas on what needs to be done to correct this short of editing entire app and adding [Serializable] to classes?
It seems like you have four choices:
- Switch back to InProc mode
- Make your objects [Serializable]
- Instead of storing high-level container objects in the Session dictionary, use lower-level objects instead, that are already serializable (such as strings, ints, etc)
- Avoid using traditional session state, and switch to some alternative state management method instead
Option 3 will generally run faster than 2, although it's also more work.
精彩评论