andrewdavey / postal

Email sending for asp.net mvc using the view engine system to render emails.
http://aboutcode.net/postal
MIT License
536 stars 168 forks source link

"The same key was already used for another template!' #147

Open Valter479 opened 8 years ago

Valter479 commented 8 years ago

I keep getting the following error:


System.InvalidOperationException

The same key was already used for another template!

System.InvalidOperationException: The same key was already used for another template!
   at RazorEngine.Templating.DelegateTemplateManager.<>c__DisplayClass1.<AddDynamic>b__0(ITemplateKey k, ITemplateSource oldSource)
   at System.Collections.Concurrent.ConcurrentDictionary`2.AddOrUpdate(TKey key, TValue addValue, Func`3 updateValueFactory)
   at RazorEngine.Templating.DelegateTemplateManager.AddDynamic(ITemplateKey key, ITemplateSource source)
   at RazorEngine.Templating.TemplateService.GetKeyAndAdd(String template, String name)
   at RazorEngine.Templating.TemplateService.GetTemplate(String razorTemplate, Object model, String cacheName)
   at RazorEngine.Templating.TemplateService.Parse(String razorTemplate, Object model, DynamicViewBag viewBag, String cacheName)
   at RazorEngine.Razor.Parse(String razorTemplate, Object model, String cacheName)
   at Postal.FileSystemRazorView.Render(ViewContext viewContext, TextWriter writer)
   at Postal.EmailViewRenderer.RenderView(IView view, ViewDataDictionary viewData, ControllerContext controllerContext, ImageEmbedder imageEmbedder)
   at Postal.EmailViewRenderer.Render(Email email, String viewName)
   at Postal.EmailService.CreateMailMessage(Email email)
   at Postal.EmailService.Send(Email email)

I am not sure why?

I am using hangfire to send email as background job.

dmbritos commented 8 years ago

I have the same issue, also using hangfire to send emails as background job. It seems to occur after editing the template while running the application. This post seems to be related (see the first item under "Explanation" in the matthid's answer):

http://stackoverflow.com/questions/29803561/razorengine-error-trying-to-send-email

jacksonmarina12 commented 5 months ago

Looks like you're encountering a key conflict issue. Have you tried checking door cable if the key is being reused elsewhere in your templates? That might help resolve the problem.