Error : Unable to serialize the session state

4 posts, 0 answers
  1. Golu
    Golu avatar
    41 posts
    Member since:
    Dec 2008

    Posted 19 Sep 2009 Link to this post

    Dear sir,
    I am using telerik dock serialized/Deserialized concept.

    but when upload on server it shows an error, it works good at local mechine, but on server shows an following error :

    in web.conf.

    <

     

    sessionState timeout="500"/>

     



    Server Error in '/Test' Application.

    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.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: 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.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [SerializationException: Type 'Telerik.Web.UI.DockState' in Assembly 'Telerik.Web.UI, Version=2009.2.701.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4' is not marked as serializable.]
       System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +7733643
       System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +258
       System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +111
       System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter) +283
       System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter) +45
       System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo) +178
       System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +7631288
       System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +461
       System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +134
       System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1577
    
    [HttpException (0x80004005): 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.]
       System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1662
       System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(Object value, BinaryWriter writer) +34
       System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter writer) +606
       System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData item, Stream stream) +239
       System.Web.SessionState.SessionStateUtility.SerializeStoreData(SessionStateStoreData item, Int32 initialStreamSize, Byte[]& buf, Int32& length) +72
       System.Web.SessionState.OutOfProcSessionStateStore.SetAndReleaseItemExclusive(HttpContext context, String id, SessionStateStoreData item, Object lockId, Boolean newItem) +87
       System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +560
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    

    can u plz give me a solution ASAP

    thanks with regards
  2. Pero
    Admin
    Pero avatar
    1156 posts

    Posted 21 Sep 2009 Link to this post

    Hi,

    This error is thrown because the DockState is not marked as serializable and ASP.NET requires the objects to be serializable to store them in the Session (when mode is "StateServer" or "SQLServer"). To overcome this problem you should serialize the state "manually" before it is stored in the Session.

    For your convenience I have modified the my portal example to serialize the state of the RadDock's before it is stored in the Session. Please find the modified project attached to this thread.

    If you have other questions, please do contact us.



    Regards,
    Pero
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joshua Grippo
    Joshua Grippo avatar
    10 posts
    Member since:
    Nov 2009

    Posted 10 Dec 2009 Link to this post

    I have run into the same problem with several Telerik Controls including RadTree and GridSortExpression. Why are these things not marked as Serializable? It is a very simple attribute to add and it should be a common expectation that these things will be serialized to session state, because the majority of enterprise web sites are going away from storing things in actual viewstate and opting for session state in the db instead.
  5. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 15 Dec 2009 Link to this post

    Hello Joshua,

    Storing controls in the Session is not recommended in any case and will likely lead to unexpected results and memory leaks. We have a detailed explanation here:
    http://blogs.telerik.com/atanaskorchev/posts/08-09-19/don_t_store_asp_net_controls_in_session_application_or_cache.aspx

    Marking GroupByExpressions with Serializable attribute will not help since they contain ArrayList internally which is not directly serializable. The options that you can consider are:

    - Invoking the ToString() method of the SortExpressions collection and using StringWriter and LosFormatter to serialize/deserialize the expressions as shown in this help topic:
    http://www.telerik.com/help/aspnet-ajax/grdsavingsettingsonperuserbasis.html

    - Casting the SortExpressions collection to IStateManager and invoking explicitly its SaveViewState()/LoadViewState() methods.

    I hope this helps.

    Greetings,
    Tsvetomir Tsonev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top