locked
Type '' in Assembly '' is not marked as serializable. linq-to-sql RRS feed

  • Question

  • User-1532916674 posted

    I am using asp.net and have configured the sessions to stored in SQL server.  My porject has many object and several linq-to-sql dbml's.  I have configured all the them to have unidirectional serialization and also made a few customized changes.

    When I run the app I keep getting this error in my application_error event handler

    Type 'Data.Karaoke.spCWP_SelUserPrivilegesResult' in Assembly 'App_Code.thzd8p2j, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.

    from the error I am not sure if it is coming from the dbml.designer.cs file which this is the code:

        [Function(Name="dbo.spCWP_SelUserPrivileges")]
                public ISingleResult<spCWP_SelUserPrivilegesResult> spCWP_SelUserPrivileges([Parameter(Name="IDCWPUser", DbType="Int")] System.Nullable<int> iDCWPUser)
                {
                    IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), iDCWPUser);
                    return ((ISingleResult<spCWP_SelUserPrivilegesResult>)(result.ReturnValue));
                }

    and

        [DataContract()]
            public partial class spCWP_SelUserPrivilegesResult
            {
                
                private int _IDTypeCWPModule;
                
                private string _TypeKey;
                
                private bool _Security;
                
                public spCWP_SelUserPrivilegesResult()
                {
                }
                
                [Column(Storage="_IDTypeCWPModule", DbType="Int NOT NULL")]
                [DataMember(Order=1)]
                public int IDTypeCWPModule
                {
                    get
                    {
                        return this._IDTypeCWPModule;
                    }
                    set
                    {
                        if ((this._IDTypeCWPModule != value))
                        {
                            this._IDTypeCWPModule = value;
                        }
                    }
                }
                
                [Column(Storage="_TypeKey", DbType="VarChar(10) NOT NULL", CanBeNull=false)]
                [DataMember(Order=2)]
                public string TypeKey
                {
                    get
                    {
                        return this._TypeKey;
                    }
                    set
                    {
                        if ((this._TypeKey != value))
                        {
                            this._TypeKey = value;
                        }
                    }
                }
                
                [Column(Storage="_Security", DbType="Bit NOT NULL")]
                [DataMember(Order=3)]
                public bool Security
                {
                    get
                    {
                        return this._Security;
                    }
                    set
                    {
                        if ((this._Security != value))
                        {
                            this._Security = value;
                        }
                    }
                }
            }

    How can I determine where the error originated from?
    Or what does the error mean?

    i am unsure how to solve or what to look for to solve the issue.

    Tuesday, June 14, 2011 12:25 AM

Answers

  • User-1757793930 posted

    When a type is not marked as serializable (see Object Serialization in .Net) you are unable to save that object type into a serialzed storage medium.

    Common Serializable mediums.

    1. Session State
    2. View State
    Typically to resolve this you just need to add the [Serializable] annotation above your class. However objects containing sub objects must also be Serializable.
    From the look of your class try adding
    [Serializable]
    Under your DataContract annotation. 
    Please review the documentation for seriazing objects.
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 14, 2011 12:53 AM