When I run the project in my Visual Studio with no problem. But when I build the projects in release mode and publish to the server, The following error always occurs.
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.
It's only happen when the optimize code option is checked in the project property page.
HttpContext.Current.Session is null at the moment.
If there has no object assign into Session, everything work is fine.
Any clue for why the HttpContext.Current.Session will become null? but the HttpContext.Current.Items is still available.
None
0 Points
1 Post
Unable to serialize the session state. HttpContext.Current.Session is null
Jan 04, 2016 10:46 AM|T.Y. CJ|LINK
Dear all,
When I run the project in my Visual Studio with no problem. But when I build the projects in release mode and publish to the server, The following error always occurs.
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.
The code which throw error was:
return (ApplicationContext)((HttpContext.Current).Session[Const.SessionName.ApplicationContext]);
Here is some findings:
It's only happen when the optimize code option is checked in the project property page.
HttpContext.Current.Session is null at the moment.
If there has no object assign into Session, everything work is fine.
Any clue for why the HttpContext.Current.Session will become null? but the HttpContext.Current.Items is still available.
Any hints to solve the problem?
Thanks,
TY
Star
12330 Points
2021 Posts
Re: Unable to serialize the session state. HttpContext.Current.Session is null
Jan 05, 2016 06:02 AM|Candice Zhou|LINK
Hi T.Y. CJ,
Welcome to ASP.NET Forums!
It's working on your local machine so you don't have stateserver or sqlserver in your config file.
To me it seems to be like session state is disabled in your webconfig on the webserver where you are deploying.
Check the difference in setting for session on your local machine and deployment server.
Best Regards,
Candice Zhou