locked
Unable to serialize the session state. HttpContext.Current.Session is null RRS feed

  • Question

  • User-193413030 posted

    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

    Monday, January 4, 2016 10:46 AM

Answers

  • User614698185 posted

    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

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 5, 2016 6:02 AM