Message: RazorLight.TemplateCompilationException : Failed to compile generated Razor template:
See original GitHub issueI updated to latest Microsoft.AspNetCore.App
2.1.4 and now FluentEmail.Razor won’t work.
Any time I try to send email using a razor template now I get this exception:
RazorLight.TemplateCompilationException : Failed to compile generated Razor template:
- (3:29) The type or namespace name 'Razor' does not exist in the namespace 'RazorLight' (are you missing an assembly reference?)
- (3:63) Predefined type 'System.String' is not defined or imported
- (3:104) Predefined type 'System.Type' is not defined or imported
- (7:10) The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
- (8:10) The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
- (9:10) The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
- (10:10) The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
- (11:56) The type or namespace name 'TemplatePage<>' does not exist in the namespace 'RazorLight' (are you missing an assembly reference?)
- (11:69) Cannot define a class or member that utilizes 'dynamic' because the compiler required type 'System.Runtime.CompilerServices.DynamicAttribute' cannot be found. Are you missing a reference?
- (11:69) Predefined type 'System.Boolean' is not defined or imported
- (14:66) The return type of an async method must be void, Task or Task<T>
- (14:38) The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?)
- (14:66) 'GeneratedTemplate.ExecuteAsync()': no suitable method found to override
- (16:12) Predefined type 'System.Object' is not defined or imported
- (16:12) The name 'BeginContext' does not exist in the current context
- (16:25) Predefined type 'System.Int32' is not defined or imported
- (16:28) Predefined type 'System.Int32' is not defined or imported
- (16:31) Predefined type 'System.Boolean' is not defined or imported
- (17:12) Predefined type 'System.Object' is not defined or imported
- (17:12) The name 'WriteLiteral' does not exist in the current context
- (17:25) Predefined type 'System.String' is not defined or imported
- (18:12) Predefined type 'System.Object' is not defined or imported
- (18:12) The name 'EndContext' does not exist in the current context
- (19:12) Predefined type 'System.Object' is not defined or imported
- (19:12) The name 'BeginContext' does not exist in the current context
- (19:25) Predefined type 'System.Int32' is not defined or imported
- (19:28) Predefined type 'System.Int32' is not defined or imported
- (19:32) Predefined type 'System.Boolean' is not defined or imported
- (0:3) Predefined type 'System.Object' is not defined or imported
- (0:3) The name 'Write' does not exist in the current context
- (0:9) Predefined type 'System.Object' is not defined or imported
- (0:9) The name 'Model' does not exist in the current context
- (25:12) Predefined type 'System.Object' is not defined or imported
- (25:12) The name 'EndContext' does not exist in the current context
- (26:12) Predefined type 'System.Object' is not defined or imported
- (26:12) The name 'BeginContext' does not exist in the current context
- (26:25) Predefined type 'System.Int32' is not defined or imported
- (26:29) Predefined type 'System.Int32' is not defined or imported
- (26:34) Predefined type 'System.Boolean' is not defined or imported
- (27:12) Predefined type 'System.Object' is not defined or imported
- (27:12) The name 'WriteLiteral' does not exist in the current context
- (27:25) Predefined type 'System.String' is not defined or imported
- (28:12) Predefined type 'System.Object' is not defined or imported
- (28:12) The name 'EndContext' does not exist in the current context
- (29:12) Predefined type 'System.Object' is not defined or imported
- (29:12) The name 'BeginWriteAttribute' does not exist in the current context
- (29:32) Predefined type 'System.String' is not defined or imported
- (29:40) Predefined type 'System.String' is not defined or imported
- (29:52) Predefined type 'System.Int32' is not defined or imported
- (29:57) Predefined type 'System.String' is not defined or imported
- (29:63) Predefined type 'System.Int32' is not defined or imported
- (29:68) Predefined type 'System.Int32' is not defined or imported
- (4:0) Predefined type 'System.Object' is not defined or imported
- (4:0) The name 'WriteAttributeValue' does not exist in the current context
- (4:20) Predefined type 'System.String' is not defined or imported
- (4:24) Predefined type 'System.Int32' is not defined or imported
- (4:29) Predefined type 'System.Object' is not defined or imported
- (4:29) The name 'Model' does not exist in the current context
- (4:48) Predefined type 'System.Int32' is not defined or imported
- (4:53) Predefined type 'System.Int32' is not defined or imported
- (4:57) Predefined type 'System.Boolean' is not defined or imported
- (35:12) Predefined type 'System.Object' is not defined or imported
- (35:12) The name 'EndWriteAttribute' does not exist in the current context
- (36:12) Predefined type 'System.Object' is not defined or imported
- (36:12) The name 'BeginContext' does not exist in the current context
- (36:25) Predefined type 'System.Int32' is not defined or imported
- (36:30) Predefined type 'System.Int32' is not defined or imported
- (36:33) Predefined type 'System.Boolean' is not defined or imported
- (37:12) Predefined type 'System.Object' is not defined or imported
- (37:12) The name 'WriteLiteral' does not exist in the current context
- (37:25) Predefined type 'System.String' is not defined or imported
- (38:12) Predefined type 'System.Object' is not defined or imported
- (38:12) The name 'EndContext' does not exist in the current context
- (39:12) Predefined type 'System.Object' is not defined or imported
- (39:12) The name 'BeginContext' does not exist in the current context
- (39:25) Predefined type 'System.Int32' is not defined or imported
- (39:30) Predefined type 'System.Int32' is not defined or imported
- (39:34) Predefined type 'System.Boolean' is not defined or imported
- (4:27) Predefined type 'System.Object' is not defined or imported
- (4:27) The name 'Write' does not exist in the current context
- (4:33) Predefined type 'System.Object' is not defined or imported
- (4:33) The name 'Model' does not exist in the current context
- (45:12) Predefined type 'System.Object' is not defined or imported
- (45:12) The name 'EndContext' does not exist in the current context
- (46:12) Predefined type 'System.Object' is not defined or imported
- (46:12) The name 'BeginContext' does not exist in the current context
- (46:25) Predefined type 'System.Int32' is not defined or imported
- (46:30) Predefined type 'System.Int32' is not defined or imported
- (46:35) Predefined type 'System.Boolean' is not defined or imported
- (47:12) Predefined type 'System.Object' is not defined or imported
- (47:12) The name 'WriteLiteral' does not exist in the current context
- (47:25) Predefined type 'System.String' is not defined or imported
- (48:12) Predefined type 'System.Object' is not defined or imported
- (48:12) The name 'EndContext' does not exist in the current context
- (14:66) 'GeneratedTemplate.ExecuteAsync()': not all code paths return a value
Result StackTrace:
at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(GeneratedRazorTemplate razorTemplate)
at RazorLight.TemplateFactoryProvider.CreateFactory(GeneratedRazorTemplate razorTemplate)
at RazorLight.TemplateFactoryProvider.CreateFactoryAsync(String templateKey)
at RazorLight.RazorLightEngine.CompileTemplateAsync(String key)
at RazorLight.RazorLightEngine.CompileRenderAsync(String key, Object model, Type modelType, ExpandoObject viewBag)
at FluentEmail.Razor.RazorRenderer.ParseAsync[T](String template, T model, Boolean isHtml)
at FluentEmail.Razor.RazorRenderer.FluentEmail.Core.Interfaces.ITemplateRenderer.Parse[T](String template, T model, Boolean isHtml)
at FluentEmail.Core.Email.UsingTemplateFromFile[T](String filename, T model, Boolean isHtml)
I downloaded source code and ran. The exception is generated in RazorRenderer.cs
the string ITemplateRenderer.Parse<T>(string template, T model, bool isHtml)
.
Error is missing reference in RazorLight library and happens on a fresh project setup.
EDIT: The issue is resolve by updating the RazorLight version to beta1 and adding to csproj:
<PropertyGroup>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
I will create PR
Issue Analytics
- State:
- Created 5 years ago
- Comments:9
Top Results From Across the Web
Failed to compile generated Razor template ...
I had the exact same issue, but only within my published application. While debugging the worker service i didn't get the error message....
Read more >Tests using razorlight fail - Build/Test Issues
Tests using razorlight fail: Hi all. We use Razorlight (via FluentEmail) to generate emails (strings) from cshtml files (razor templates).
Read more >A brand new website interface for an even better experience!
RazorLight.Compilation.TemplateCompilationException: Failed to compile generated Razor template.
Read more >Render Emails Using Razor Templating
Learn how to use different open-source Razor engines to render Razor templates to strings for sending emails.
Read more >Error using RazorEngine Templating ...
RazorEngine.Templating.TemplateCompilationException Unable to compile template. Assuming assembly reference 'System.Web.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@aatmmr just to be sure, Can you check if you have the correct using in your file.
I think in .Net Core 3, you should use
<PreserveCompilationContext>true</PreserveCompilationContext>
<PreserveCompilationReferences>true</PreserveCompilationReferences>