I have followed this tutorial to use the RazorEngine to generate HTML emails (without ASP.NET MVC). It worked fine when I used either a strongly typed view or an anonymous object as the model:
Layout.cshtml
@model dynamic
// html contents...
C# snippet
var template = Encoding.UTF8.GetString(Properties.Resources.ContractList);
var model = new
{
ContractList = list
};
var templateService = new TemplateService();
var html = templateService.Parse(template, model, null, null);
Then I gave it a cache name, as recommended on the third part of the tutorial:
templateService.Parse(template, model, null, nameof(Properties.Resources.ContractList));
It worked fine with the strongly typed object, but with the anonymous object I started receiving this message as of the second time it ran:
Invalid token for impersonation - it cannot be duplicated
How can I resolve this and still use an anonymous object for the model?
I have seen solutions (here, here) that suggest transforming the anonymous object to an ExpandoObject
, but I'd like to avoid that if possible.