我必须创建一个能够发送电子邮件的 Asp.Net Web Api。
我成功发送了电子邮件,但仅使用存储在本地变量中的简单模板。
下一步是从外部文件渲染模板,如下所示:
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;
}
问题是,当razor引擎尝试解析模板时,会出现以下错误:
"Could not load type 'System.Security.Principal.WindowsImpersonationContext' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."
我试图从字符串中解析模板,并且我也因相同的错误而被阻止。
你可能会看到
<PackageReference Include="RazorEngine" Version="3.10.0" />
或 .csproj 文件中的类似内容,当您真正需要的是
<PackageReference Include="RazorEngine.Netcore" Version="3.1.0" />
so,
$ dotnet remove package RazorEngine
$ dotnet add package RazorEngine.Netcore --version 3.1.0
(或与版本更新类似)看起来好像就是答案
[马特的答案有一个“建议的编辑队列已满”标志]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)