Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 340109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:35:08+00:00 2026-05-12T10:35:08+00:00

I get a serialization error on a page containing a custom control. the control

  • 0

I get a serialization error on a page containing a custom control. the control has a member (dataContext) of a type (EntityContext) that is non-serializable, and marked as such.

this is the error:

Type ‘Entities.EntityContext’ in
Assembly ‘…’ is not marked as
serializable.

[SerializationException: Type
‘…Entities.EntityContext’
in Assembly ‘…’ 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(Object
obj, ISurrogateSelector
surrogateSelector, StreamingContext
context, SerObjectInfoInit
serObjectInfoInit, IFormatterConverter
converter, ObjectWriter objectWriter)
+161 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object
obj, ISurrogateSelector
surrogateSelector, StreamingContext
context, SerObjectInfoInit
serObjectInfoInit, IFormatterConverter
converter, ObjectWriter objectWriter)
+51 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object
graph, Header[] inHeaders,
__BinaryWriter serWriter, Boolean fCheck) +410
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream
serializationStream, Object graph,
Header[] headers, Boolean fCheck) +134
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream
serializationStream, Object graph) +13
System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter
writer, Object value) +4966

[ArgumentException: Error serializing
value
‘…Entities.EntityContext’
of type
‘…Entities.EntityContext.’]
System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter
writer, Object value) +5425
System.Web.UI.ObjectStateFormatter.Serialize(Stream
outputStream, Object stateGraph) +163
System.Web.UI.ObjectStateFormatter.Serialize(Object
stateGraph) +99
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Serialize(Object
state) +37
System.Web.UI.Util.SerializeWithAssert(IStateFormatter
formatter, Object stateGraph) +55
System.Web.UI.HiddenFieldPageStatePersister.Save()
+143 System.Web.UI.Page.SavePageStateToPersistenceMedium(Object
state) +190
System.Web.UI.Page.SaveAllState()
+1466 System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean
includeStagesAfterAsyncPoint) +5477

This is the control:

public class EntityDataSource : ObjectDataSource
{
    [NonSerialized] private EntityContext dataContext;

    /// <summary>
    /// Gets the data context. (This is used by the page at runtime.)
    /// </summary>
    /// <value>The data context.</value>
    // ReSharper disable MemberCanBePrivate.Global
    public EntityContext DataContext
    // ReSharper restore MemberCanBePrivate.Global
    {
        get { return dataContext; }
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        dataContext = new EntityContext(SessionProvider.GetContext());
    }

    /// <summary>
    /// Viewstate is not implemented. This value allways return <c>false</c>.
    /// </summary>
    /// <exception cref="NotSupportedException">Exception is thrown when setting this value.</exception>
    [Browsable(false)]
    public override bool EnableViewState
    {
        get
        {
            return false;
        }
        set
        {
            //Throws exception if value is true.
            if (value)
            {
                throw new NotSupportedException("Viewstate is not enabled on this control.");
            }
        }
    }

    public override void Dispose()
    {
        if (DataContext != null)
        {
            DataContext.Dispose();
        }

        base.Dispose();
    }
}

It almost seems like the page doesn’t honor the NonSerializedAttribute.
I have omitted the company and product names from the namespaces.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:35:08+00:00Added an answer on May 12, 2026 at 10:35 am

    If I am understanding the problem …

    I take it the instance is beeing serialized and you wish it not to be so. Well, if you cannot change the way the instance is handled, change the way it serializes. Implement System.Runtime.Serialization.ISerializable and just set the initial state in the deserialization constructor (required when implementing the interface). This way at least you circumvent the exception (be sure this still results in correct behaviour) and you add nothing much to the stream (other than type information). As you need no state persisted, you simply do not add items to the dictionary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 175k
  • Answers 175k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this: $('#myDiv').click(function(evt) { if (evt.target.type !== 'checkbox') { var… May 12, 2026 at 3:00 pm
  • Editorial Team
    Editorial Team added an answer You are probably referring to beautytips, a Drupal module implementation… May 12, 2026 at 3:00 pm
  • Editorial Team
    Editorial Team added an answer Based only on the information you've given, I'd make it… May 12, 2026 at 3:00 pm

Related Questions

I am using Telerik controls in my webforms and want to serialize object on
Guys, I can't seem to get the object serialization working correctly clientside for my
I've got a problem with a SOAP Web Reference that was generated by Visual
I have created a non-visual component in C# which is designed as a placeholder

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.