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....