I have to create a Asp.Net Web Api that is capable of sending emails. I managed in sending the email but only with a simple template stored in a variable, locally. The next step was to render a template from external file, like this:
string filePath = @"C:\Data\EmailClient\EmailClient\EmailClient\EmailTemplate\ReceiptTemplate.cshtml";
var config = new TemplateServiceConfiguration
{
TemplateManager = new ResolvePathTemplateManager(new[] { "EmailTemplates" }),
DisableTempFileLocking = true
};
Engine.Razor = RazorEngineService.Create(config);
if (File.Exists(filePath))
{
emailHtmlBody = Engine.Razor.RunCompile(filePath, null, email);
mail.Body = emailHtmlBody;
}
The problem is that, when the razor engine tries to parse the template, the following error appears:
"Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."
I was trying to parse the template from a string, and I am blocked with the same error, also.
using System.Security
orusing System.Security.AccountManagement
– Palmira