locked
Error: Unable to serialize the session state. RRS feed

  • Question

  • Hi all,

    I have an web application which is migrated to Azure. Everything seems to be working fine EXCEPT for this ERROR which is popping after you click an OK button in the page to redirect to another page.

    What I am doing in this page is :

    - I have an iFrame into which HTML files get loaded. The user has to finish few tasks in this page. AJAX is used to load the HTML files when required.

    - After the tasks are completed, there is an OK button on the page that has to be clicked.

    As soon as the OK button is clicked i get this ERROR

    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 am using Azure Table storage to store the sessions. The sessions are working fine otherwise except in this page while exiting the task and redirecting to another page.

    By the way WHERE SHOULD I USE THE

    "<Serializable()> _ " attribute. I have used it in all the pages that are lead to the page where I get this error and also on the error page.

    This didnt work for me.  

    Can anyone please help me with this.

    Thursday, August 18, 2011 8:53 AM

Answers

  • Hi Sandeep,

    > By the way WHERE SHOULD I USE THE "<Serializable()> _ " attribute.

    The Serializable attribute should be used to mark the class definition if you want to store the instance of that class in out of process Session. For example:

      protected void Page_Load(object sender, EventArgs e)
      {
        MyItem item = new MyItem() { Field1 = "Hello" };
        Session["item1"] = item;
      }
    
      [Serializable]
      public class MyItem
      {
        public string Field1 { get; set; }
        public SubItem SubItem { get; set; }
          
      }
      [Serializable]
      public class SubItem
      {
     
      }
    

    If you are not able to resolve the issue by referring to above code, sharing the code that you store data in Session will be helpful.

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    • Marked as answer by MBytes Saturday, August 20, 2011 9:16 AM
    Friday, August 19, 2011 6:07 AM
  • Hi Sandeep,

    This is not a session provider error. This error is thrown because the objects stored in session state are not serializable. Please see SerializableAttribute Class for more information.

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    • Proposed as answer by Seetha_ Friday, August 19, 2011 8:23 AM
    • Marked as answer by MBytes Saturday, August 20, 2011 9:16 AM
    Friday, August 19, 2011 7:49 AM
  • Hi all,

    I was getting this error because I was storing a datarow in the session.

    I removed it and it worked fine.

    Thanks to all who helped me.

    Regards

    Sandeep

    • Marked as answer by MBytes Saturday, August 20, 2011 5:14 AM
    Saturday, August 20, 2011 5:14 AM

All replies

  • Hi all,

    I have an web application which is migrated to Azure. Everything seems to be working fine EXCEPT for this ERROR which is popping after you click an OK button in the page to redirect to another page.

    What I am doing in this page is :

    - I have an iFrame into which HTML files get loaded. The user has to finish few tasks in this page. AJAX is used to load the HTML files when required.

    - After the tasks are completed, there is an OK button on the page that has to be clicked.

    As soon as the OK button is clicked i get this ERROR

    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 am using Azure Table storage to store the sessions. The sessions are working fine otherwise except in this page while exiting the task and redirecting to another page.

    By the way WHERE SHOULD I USE THE

    "<Serializable()> _ " attribute. I have used it in all the pages that are lead to the page where I get this error and also on the error page.

    This didnt work for me.  

    Can anyone please help me with this.

     

    Regards

    Sandeep

    • Merged by Wenchao Zeng Friday, August 19, 2011 7:41 AM the same question
    Thursday, August 18, 2011 10:43 AM
  • the serializable attribute should go on the classes you are putting into the session bag. Odds are you have an object you've put in the session that isn't serializable, so be sure to check any imbedded objects (inside collections).
    Thursday, August 18, 2011 12:26 PM
  • Hey Brent,

    Can you please tell me how you check for objects inside collections.

    Regards

    Sandeep

    Friday, August 19, 2011 4:23 AM
  • Hi Sandeep,

    > By the way WHERE SHOULD I USE THE "<Serializable()> _ " attribute.

    The Serializable attribute should be used to mark the class definition if you want to store the instance of that class in out of process Session. For example:

      protected void Page_Load(object sender, EventArgs e)
      {
        MyItem item = new MyItem() { Field1 = "Hello" };
        Session["item1"] = item;
      }
    
      [Serializable]
      public class MyItem
      {
        public string Field1 { get; set; }
        public SubItem SubItem { get; set; }
          
      }
      [Serializable]
      public class SubItem
      {
     
      }
    

    If you are not able to resolve the issue by referring to above code, sharing the code that you store data in Session will be helpful.

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    • Marked as answer by MBytes Saturday, August 20, 2011 9:16 AM
    Friday, August 19, 2011 6:07 AM
  • Hi Sandeep,

    This is not a session provider error. This error is thrown because the objects stored in session state are not serializable. Please see SerializableAttribute Class for more information.

    Thanks.


    Wenchao Zeng
    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com.
    Microsoft One Code Framework
    • Proposed as answer by Seetha_ Friday, August 19, 2011 8:23 AM
    • Marked as answer by MBytes Saturday, August 20, 2011 9:16 AM
    Friday, August 19, 2011 7:49 AM
  • Hi all,

    I was getting this error because I was storing a datarow in the session.

    I removed it and it worked fine.

    Thanks to all who helped me.

    Regards

    Sandeep

    • Marked as answer by MBytes Saturday, August 20, 2011 5:14 AM
    Saturday, August 20, 2011 5:14 AM