question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when trying to render from .NET 6 project

See original GitHub issue

Describe the bug I have RazorLight set up in a shared project that multitargets both net48 and net6.0. I have a web project that targets 4.8, and when using RazorLight via the previously mentioned shared project it works fine. I also have a console project that targets net6.0. When attempting to use the same shared project it fails with the below error.

I see that there are several bugs describing a similar error. I’ve tried all of the suggestions on these other issues in addition to the troubleshooting steps outlined in the readme.

Thanks in advance for the help!

To Reproduce Setup: RazorLightEngine razorLightEngine = new RazorLightEngineBuilder() .SetOperatingAssembly(type.Assembly) .UseFileSystemProject(templatePath) .UseMemoryCachingProvider() .Build();

Execution: string renderedContent = await razorLightEngine.CompileRenderAsync(key, model, (ExpandoObject)ViewBag);

Expected behavior The template is rendered without error.

Information (please complete the following information):

  • OS: Windows 10
  • Platform: .NET Framework 4.8, .NET 6
  • RazorLight version: 2.3.0
  • Are you using the OFFICIAL RazorLight package? Yes
  • Visual Studio version: Visual Studio Enterprise 17.3.6

Additional context Quartz.SchedulerException: Job threw an unhandled exception. —> RazorLight.Compilation.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?) - (1:6) The type or namespace name ‘GDIT’ could not be found (are you missing a using directive or an assembly reference?) - (25:37) The type or namespace name ‘TemplatePage<>’ could not be found (are you missing a using directive or an assembly reference?) - (25:50) The type or namespace name ‘LeaveNotification’ could not be found (are you missing a using directive or an assembly reference?) - (28:66) ‘GeneratedTemplate.ExecuteAsync()’: no suitable method found to override - (4:4) The name ‘Layout’ does not exist in the current context - (5:30) The name ‘Model’ does not exist in the current context - (6:8) The name ‘Model’ does not exist in the current context - (6:55) The name ‘Model’ does not exist in the current context - (6:98) The name ‘Model’ does not exist in the current context - (8:38) The name ‘Model’ does not exist in the current context - (43:12) The name ‘WriteLiteral’ does not exist in the current context - (12:38) The name ‘Write’ does not exist in the current context - (12:44) The name ‘Model’ does not exist in the current context - (51:12) The name ‘WriteLiteral’ does not exist in the current context - (12:99) The name ‘Write’ does not exist in the current context - (59:12) The name ‘WriteLiteral’ does not exist in the current context - (60:12) The name ‘BeginWriteAttribute’ does not exist in the current context - (15:0) The name ‘WriteAttributeValue’ does not exist in the current context - (15:67) The name ‘ViewBag’ does not exist in the current context - (15:84) The name ‘Model’ does not exist in the current context - (68:12) The name ‘EndWriteAttribute’ does not exist in the current context - (69:12) The name ‘WriteLiteral’ does not exist in the current context - (15:131) The name ‘Write’ does not exist in the current context - (15:175) The name ‘ViewBag’ does not exist in the current context - (15:193) The name ‘Model’ does not exist in the current context - (77:12) The name ‘WriteLiteral’ does not exist in the current context

See CompilationErrors for detailed information

     at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(IGeneratedRazorTemplate razorTemplate)
     at RazorLight.Compilation.RazorTemplateCompiler.CompileAndEmitAsync(RazorLightProjectItem projectItem)
     at RazorLight.Compilation.RazorTemplateCompiler.OnCacheMissAsync(String templateKey)
     at RazorLight.Compilation.RazorTemplateCompiler.OnCacheMissAsync(String templateKey)
     at RazorLight.EngineHandler.CompileTemplateAsync(String key)
     at RazorLight.EngineHandler.CompileRenderAsync[T](String key, T model, ExpandoObject viewBag)
     at Notifications.Jobs.JobBase`1.BuildTemplate(String template, Object model) in Source\Notifications\Jobs\JobBase.cs:line 285
     at Notifications.Jobs.Leave.NewLeave.BuildMessage() in Source\Notifications\Jobs\Leave\NewLeave.cs:line 28
     at Notifications.Jobs.Leave.NewLeave.Execute(IJobExecutionContext context) in Notifications\Jobs\Leave\NewLeave.cs:line 41
     at Quartz.Core.JobRunShell.Run(CancellationToken cancellationToken)
     --- End of inner exception stack trace --- [See nested exception: RazorLight.Compilation.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?)
  - (1:6) The type or namespace name 'Project' could not be found (are you missing a using directive or an assembly reference?)
  - (25:37) The type or namespace name 'TemplatePage<>' could not be found (are you missing a using directive or an assembly reference?)
  - (25:50) The type or namespace name 'LeaveNotification' could not be found (are you missing a using directive or an assembly reference?)
  - (28:66) 'GeneratedTemplate.ExecuteAsync()': no suitable method found to override
  - (4:4) The name 'Layout' does not exist in the current context
  - (5:30) The name 'Model' does not exist in the current context
  - (6:8) The name 'Model' does not exist in the current context
  - (6:55) The name 'Model' does not exist in the current context
  - (6:98) The name 'Model' does not exist in the current context
  - (8:38) The name 'Model' does not exist in the current context
  - (43:12) The name 'WriteLiteral' does not exist in the current context
  - (12:38) The name 'Write' does not exist in the current context
  - (12:44) The name 'Model' does not exist in the current context
  - (51:12) The name 'WriteLiteral' does not exist in the current context
  - (12:99) The name 'Write' does not exist in the current context
  - (59:12) The name 'WriteLiteral' does not exist in the current context
  - (60:12) The name 'BeginWriteAttribute' does not exist in the current context
  - (15:0) The name 'WriteAttributeValue' does not exist in the current context
  - (15:67) The name 'ViewBag' does not exist in the current context
  - (15:84) The name 'Model' does not exist in the current context
  - (68:12) The name 'EndWriteAttribute' does not exist in the current context
  - (69:12) The name 'WriteLiteral' does not exist in the current context
  - (15:131) The name 'Write' does not exist in the current context
  - (15:175) The name 'ViewBag' does not exist in the current context
  - (15:193) The name 'Model' does not exist in the current context
  - (77:12) The name 'WriteLiteral' does not exist in the current context

See CompilationErrors for detailed information

     at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(IGeneratedRazorTemplate razorTemplate)
     at RazorLight.Compilation.RazorTemplateCompiler.CompileAndEmitAsync(RazorLightProjectItem projectItem)
     at RazorLight.Compilation.RazorTemplateCompiler.OnCacheMissAsync(String templateKey)
     at RazorLight.Compilation.RazorTemplateCompiler.OnCacheMissAsync(String templateKey)
     at RazorLight.EngineHandler.CompileTemplateAsync(String key)
     at RazorLight.EngineHandler.CompileRenderAsync[T](String key, T model, ExpandoObject viewBag)
     at Notifications.Jobs.JobBase`1.BuildTemplate(String template, Object model) in Source\Notifications\Jobs\JobBase.cs:line 285
     at Notifications.Jobs.Leave.NewLeave.BuildMessage() in Source\Notifications\Jobs\Leave\NewLeave.cs:line 28
     at Notifications.Jobs.Leave.NewLeave.Execute(IJobExecutionContext context) in Source\Notifications\Jobs\Leave\NewLeave.cs:line 41
     at Quartz.Core.JobRunShell.Run(CancellationToken cancellationToken)]

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
doxxxcommented, Dec 13, 2022

“Proprietary templating system” was just a convenient shorthand for “closed source code base which makes use of templating so I can’t just cut & paste my code to show you the problem”. I am not simply wrapping RazorLight to re-sell.

For more context, it’s a web server framework with object remoting over WebSockets, templating, and the rest of the kitchen sink, developed internally many years ago, which all of our applications depend on. If we want to make progress towards .NET 6, we need to port this framework so as to avoid rewriting all of our applications to use something else.

@czielin My project needs a custom template page base class because it adds some methods and properties for pages to use (e.g. dependency injection, HTTP context). That may be a bad way of doing things, but as an existing framework, other projects depend on the feature set it provides, so I can’t just change it.

Ultimately, my goal is to get applications using Blazor where appropriate, but to get there they first need to work on .NET 6 with the existing frameworks.

1reaction
doxxxcommented, Dec 13, 2022

I had to alter my TemplateBase class (as referenced in the template above) to inherit from RazorLight’s TemplatePage.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NET 6 Core Web App Returns web page not found
I have created 3 projects with equivalent settings in NET6 and 1 project in NET5. The issue occurs in each NET6 app, but...
Read more >
asp.net core mvc - MVC6 unable to render the page
Open a browser to the listening port and the error will be displayed in the cmd window. If your project doesn't build/run under...
Read more >
View component not being rendered using tag helper syntax
I am trying to use a view component using the tag helper syntax ... NET 6.0 on Windows in projects running by dotnet...
Read more >
Server-side rendering in ASP.NET Core Angular
I've been trying to get Server-side rendering working in the Angular ... Now when you'd try to run the project, you'll probably get...
Read more >
Render Telerik Blazor component in Javascript throws ...
I created a "Telerik C# Blazor Application" template, with .NET6, Hosting Model Server, Target Framework .NET 6.0, CRUD template. (Attached).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found