locked
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. RRS feed

  • Question

  • User-731412649 posted

    Hi Team,

    I am facing the below listed issue while trying to make use of the serializable object in C#. I have used the below code snippet

    Session Used

    Session["YYY"] = dt;

    The session variable was losing its value after the execution of the method in which the declaration was made. Hence had to go with the below listed config for setting the timeout to 940.

    Web config

    <sessionState mode="StateServer" cookieless="false" timeout="940" />

    Received the below error after making the above change

    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.

    Had marked the class as serializable as shown below

    [Serializable()]

    public class xyz

    {

    }

    Saturday, December 26, 2015 8:57 PM

All replies

  • User753101303 posted

    Hi,

    And which types are you using in your xyz class definition? More likely they are not all serializable.

    Saturday, December 26, 2015 11:55 PM
  • User-731412649 posted

    Hi Patrice,

    I am able to find the rootcause of my issue now I had added the web config entry with session that has caused the issue with the error message.  I had added this because the value stored in my session variable loses its content when I actually hit the finally block. So is there any option to deal with this because I would require the value again to be used in another method downstream.

    Sunday, December 27, 2015 8:52 PM
  • User-731412649 posted

    Also I have tried storing the value in Static variable but even that loses the value in the finally block.

    Sunday, December 27, 2015 9:06 PM
  • User753101303 posted

    Good point. It is always better to solve your actual problem rather than to just try something else without even understanding your initial issue.

    Showing some code could help. Could it be that you are disposing the object you are trying to store in the session? Or could it be that the web app is restarting?

    Sunday, December 27, 2015 10:02 PM
  • User614698185 posted

    Hi Arvind,

    It seems to be like session state is disabled in your web config 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

    Tuesday, December 29, 2015 8:51 AM