Home - Forums-.NET - FlyTreeView (ASP.NET) - Serialization exception after upgrade

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Serialization exception after upgrade
Link Posted: 02-Apr-2008 06:02
I just upgraded from 4.1.5 to 4.3.217 and I am getting the following when trying to view a page containing the control:

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.
Link Posted: 02-Apr-2008 06:47
Brian,

FlyTreeView does not use Session state in any manner.

Could you please also provide stack trace of the error?
Link Posted: 02-Apr-2008 06:52
Certainly...thanks for the quick response...here is the entire error message

Server Error in '/Web.Tracker' 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 'NineRays.WebControls.FlyTreeNodePadding' in Assembly 'NineRays.WebControls.FlyTreeView, Version=4.3.2.17, Culture=neutral, PublicKeyToken=821883bc279978e2' is not marked as serializable.]
   System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +2700482
   System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +245
   System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +88
   System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) +175
   System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter) +50
   System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +438
   System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +131
   System.Web.Util.AltSerialization.WriteValueToStream(Object value, BinaryWriter writer) +1513

[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) +1602
   System.Web.SessionState.SessionStateItemCollection.WriteValueToStreamWithAssert(Object value, BinaryWriter writer) +34
   System.Web.SessionState.SessionStateItemCollection.Serialize(BinaryWriter writer) +627
   System.Web.SessionState.SessionStateUtility.Serialize(SessionStateStoreData item, Stream stream) +257
   System.Web.SessionState.SessionStateUtility.SerializeStoreData(SessionStateStoreData item, Int32 initialStreamSize, Byte[]& buf, Int32& length) +60
   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) +476
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
Link Posted: 02-Apr-2008 06:53
Also - we are not placing the item in the session...it is contained within a user control....
Link Posted: 02-Apr-2008 07:06
It looks like somehow FlyTreeView is added to session state.
Please try to see what you have in Session collection (probably at Render or even Unload page executing stage).

Of course, we can simply try to mark FlyTreeNodePadding class as serializable, but this is not the right way.
The right way is to determine a reason why FlyTreeView control (or some of its settings) are placed into Session.
Link Posted: 02-Apr-2008 07:23
I checked the code - definately none of the nodes or the tree are being placed into the session....
[code]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using EMSolution.Domain.Organization;
using EMSolution.Domain.User;
using EMSolution.Service;
using EMSolution.Service.Organization;
using EMSolution.Service.User;
using NineRays.WebControls;
using Web.SharedUI.Utils;

namespace Web.SharedUI.SharedUI.App_SharedUserControls
{
    public delegate void SelectionWasChangedEventHandler(object sender, EventArgs e);

    public partial class DropDownTreeView_OrgUnits : UserControl
    {
        [Browsable(true)]
        public bool Enabled
        {
            get { return ViewState["Enabled"] == null ? true : (bool) ViewState["Enabled"]; }
            set { ViewState["Enabled"] = value; }
        }

        [Browsable(true)]
        public bool Required
        {
            get { return ViewState["Required"] == null ? false : (bool) ViewState["Required"]; }
            set
            {
                ViewState["Required"] = value;                
            }
        }

        [Browsable(true)]
        public bool PostBackOnSelect
        {
            get { return (ViewState["PostBackOnSelect"] == null ? false : (bool) ViewState["PostBackOnSelect"]); }
            set { ViewState["PostBackOnSelect"] = value; }
        }

        [Browsable(true)]
        public bool LimitToUserRoot
        {
            get { return (ViewState["LimitToUserRoot"] == null ? false : (bool)ViewState["LimitToUserRoot"]); }
            set { ViewState["LimitToUserRoot"] = value; }
        }

        [Browsable(true)]
        public string ValidationGroup
        {
            get { return ViewState["ValidationGroup"] as String; }
            set { ViewState["ValidationGroup"] = value; }
        }

        [Browsable(true)]
        public string DisplayText
        {
            get { return ViewState["DisplayText"] as String; }
            set { ViewState["DisplayText"] = value; }
        }

        [Browsable(true)]
        public string NullSelectionText
        {
            get { return ViewState["NullSelectionText"] as String; }
            set
            {
                ViewState["NullSelectionText"] = value;
                if (ChoiceValue.Value == NullSelectionValue)
                {
                    ChoiceText.Text = value;
                }
            }
        }

        [Browsable(true)]
        public string NullSelectionValue
        {
            get { return ViewState["NullSelectionValue"] as String; }
            set { ViewState["NullSelectionValue"] = value; }
        }

        public string SelectedValue
        {
            get
            {
                if (treeOrgUnits.SelectedNode != null)
                {
                    return treeOrgUnits.SelectedNode.Value;
                }
                return null;
            }
            set
            {
                treeOrgUnits.SelectedNode = null;

                FlyTreeNode node = FindNode(treeOrgUnits, value);
                if (node != null)
                {
                    node.Selected = true;

                    FlyTreeNode p = node.Parent;
                    while (p != null)
                    {
                        p.Expanded = true;
                        p = p.Parent;
                    }
                }
            }
        }

        public string SelectedText
        {
            get
            {
                if (treeOrgUnits.SelectedNode != null)
                {
                    return treeOrgUnits.SelectedNode.Text;
                }
                return null;
            }
        }

        public bool HasValue(string strKey)
        {
            FlyTreeNode node = FindNode(treeOrgUnits, strKey);
            if (node != null)
            {
                return true;
            }

            return false;
        }

        public event SelectionWasChangedEventHandler SelectionChanged;

        protected virtual void OnSelectionChanged(object sender,
                                                  EventArgs e)
        {
            if (SelectionChanged != null)
            {
                SelectionChanged(this, e);
            }
        }

        private void RegisterScripts()
        {
            string strKey = "treeviewjs" + ClientID;
            Page.ClientScript.RegisterClientScriptBlock(GetType(),
                                                        strKey,
                                                        @"