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

  • SEARCH
  • Home
  • 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 8163033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:55:41+00:00 2026-06-06T18:55:41+00:00

I have a model that looks like: [Serializable] public class TemplatePageModel { public PageModel

  • 0

I have a model that looks like:

[Serializable]
public class TemplatePageModel
{
    public PageModel Page { get; set; }
    public SidebarModel Sidebar { get; set; }
}

[Serializable]
public class PageModel
{
    public IEnumerable<SectionModel> Section { get; set; }
}

[Serializable]
public class SidebarModel
{
    public IEnumerable<ControlModel> Control { get; set; }
}

[Serializable]
public class SectionModel
{
    public string Order { get; set; }

    public string Editable { get; set; }

    public string Column { get; set; }

    public string Text { get; set; }
}

I’m then trying to cache this in memcached using EnyimMemcached.

No exceptions are thrown, but the item isn’t stored.
I’ve tracked this down to the fact that my TemplatePageModel class isn’t serializable.

I tested this with this little snippet:

MemoryStream mem = new MemoryStream();
BinaryFormatter b = new BinaryFormatter();
try
{
    b.Serialize(mem, result);
}
catch (Exception ex)
{
    //EXCEPTION HERE
}

It’s complaining about my IEnumerable properties.

Actual error message is:

Type
‘System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[System.Xml.Linq.XElement,
System.Xml.Linq, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[Desktop.Service.Model.ControlModel,
Dekstop.Service, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]]’ in Assembly ‘System.Core, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089’ is not marked as
serializable.

How can I get round this?

I was hoping not to have to serialize into json first, and de-serialize on the way out if possible….

  • 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-06-06T18:55:43+00:00Added an answer on June 6, 2026 at 6:55 pm

    BinaryFormatter is a field-level serializer. It won’t care whether something is IEnumerable etc. It just cares about: “what is the actual object here? can I serialize it?”. For example, an array or list is generally serializable. Some custom deferred sequence (maybe a filtered LINQ expression) is potentially not serializable.

    Perhaps an even easier option: don’t try to serialize complex expressions. So instead of:

    obj.Controls = someQuery.Where(x => whatever).OrderBy(x => x.Foo);
    

    do:

    obj.Controls = someQuery.Where(x => whatever).OrderBy(x => x.Foo).ToArray();
    

    An array (or list) is simple and trivially serializable.

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

Sidebar

Related Questions

I have a view model that looks like this public class ViewModelRound2 { public
I have a model that looks something like this: public abstract class Parent {
I have model that looks like this: public class Lesson { public int Id
Let's say I have a model that looks like this: public class Blog {
I have a model that looks like this: [DisplayName(Subject)] public string SubjectID { get;
I have an object model that looks like this: public class MyModel { public
I have a model that looks like this: public class UserAdminEditViewModel { public User
I have a view model that looks like this: public class VenueIndexViewModel : BaseViewModel
I have a model that looks like this: public class Book { public string
I have an object model that looks like this: public class MyObjectModel { public

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.