Note that there are some explanatory texts on larger screens.

plurals
  1. PORazorEngine "Unable to compile template" Error
    primarykey
    data
    text
    <p>I'm using the following code to build and send an email using RazorEngine.</p> <pre><code>//build email using template. string template = File.OpenText(EmailTemplatePath).ReadToEnd(); OrganizationInviteEmailTemplate model = new OrganizationInviteEmailTemplate() { FirstName = Invitation.FirstName, LastName = Invitation.LastName, Message = Message, OrganizationName = Invitation.Organization.OrganizationName, ConfirmUrl = string.Format(ConfirmUrlTemplate, Invitation.InviteCode) }; string body = Razor.Parse(template, model); //email the invitation. MailMessage message = new MailMessage(); message.To.Add(Invitation.Email); message.Subject = "Invitation From " + Invitation.Organization.OrganizationName; message.Body = body; message.IsBodyHtml = true; SmtpClient client = new SmtpClient(); client.Send(message); </code></pre> <p>The template is below:</p> <pre><code> &lt;html&gt; &lt;head&gt; &lt;/head&gt; &lt;body&gt; &lt;h3&gt;@Model.OrganizationName has invited you to be part of their organization&lt;/h3&gt; &lt;p&gt; Hi @Model.FirstName, &lt;/p&gt; .....etc...... &lt;/body&gt; &lt;/html&gt; </code></pre> <p>I get the "Unable to compile template" error 9 times out of 10 and then it will work once after I adjust the template by removing <strong>Model.</strong> and/or adjusting the code to use <strong>Parse</strong> instead, but then it will go right back to not working. It's like something is caching a piece of code briefly or something.</p> <p>I'm using the RazorEngine.dll included with <a href="http://john.katsiotis.com/blog/razorjs---write-razor-inside-your-javascript-files" rel="nofollow">RazorJS</a>, version 2.1.4113.149. Maybe that's the issue. Going to try <a href="http://kazimanzurrashid.com/posts/use-razor-for-email-template-outside-asp-dot-net-mvc" rel="nofollow">this library</a> or <a href="https://github.com/andrewdavey/postal" rel="nofollow">Postal</a> next since this is taking way too much time already. Or just hard code the damn thing.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload