SerializationException: Type 'RazorEngine.Templating.ExecuteContext' is not marked as serializable.

May 14, 2012 at 11:52 AM

Hello,

I am trying to use IsolatedTemplateService and I am getting exception:

SerializationException: Type 'RazorEngine.Templating.ExecuteContext' is not marked as serializable.

Maybe it is because I am returning and using ViewBag.Title as email title.

ITemplate template = Service.Resolve(templateName, model); 
ExecuteContext executeContext = new ExecuteContext();           
string generateOutput = template.Run(executeContext);           
return new TemplateOutput(generateOutput, (string)executeContext.ViewBag.Title);

With TemplateService it is working without problems.

The question: How to use IsolatedTemplateService and return and use ViewBag?

The RazorEngine version is:3.0.8.0

Jan 26 at 11:21 AM
Edited Jan 26 at 11:26 AM