Error compiling: The type or namespace name 'Razor' does not exist in the namespace 'RazorLight'...
See original GitHub issueDescribe the bug When attempting to compile a string template and a complex model, we get the error:
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?)
To Reproduce
- .Net Framework 4.7.2
- Project is an ASP.NET solution with .cshtml views, which work fine
- Use a non-trivial string template with references to C# POCOs (a simple “Hello World” string works fine)
Expected behavior
- The
CompileRenderStringAsync()
function returns the result
Information (please complete the following information):
- OS: Windows 10 (dev environment)
- Platform: .NET Framework 4.7.2
- RazorLight version: 2.0.0-rc.3 (latest)
- Are you using the OFFICIAL RazorLight package? https://www.nuget.org/packages/razorlight (I installed it with Package Manager as recommended on your main page)
- Visual Studio version: VS Professional 2019 Version 16.8.2 (latest)
Additional context
Clearly the library is referenced - there would be no way to call the .CompileRenderStringAsync()
method otherwise. And it does build and compile fine.
I tried these things:
- Added the
<PropertyGroup>
settings you mentioned (all of them) in the ASP.NET .csproj file. It didn’t change anything - and also those might apply only to .Net Core?
I don’t think this is an issue with your library necessarily - it’s just unclear how to figure this out.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:11
Top Results From Across the Web
Razor The type or namespace could not be found
I had this issue with a (ASP).NET Core project. The root cause was because the .csproj file was automagically updated after I mistakenly...
Read more >RazorLight
EmbeddedResource source. For embedded resource, the key is the namespace of the project where the template exists combined with the template's file name....
Read more >RazorLight
Failed to compile generated Razor template: - (3:29) The type or namespace name 'Razor' does not exist in the namespace 'RazorLight' (are you...
Read more >Razor syntax reference for ASP.NET Core
Razor is a markup syntax for embedding .NET based code into webpages. The Razor syntax consists of Razor markup, C#, and HTML. Files...
Read more >I'm getting this issue: the type or namespace name 'Mvc' ...
I'm getting this issue: the type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspnetCore' (are you missing an assembly reference?)...
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
This issue caused by .SetOperatingAssembly(typeof(OurWebApp.Data.Order).Assembly)
If your model is dynamic object, it will give you above errors. Be careful if you just simply remove this, RazorLightEngine.Build() will try to get the Assembly
Assembly assembly = operatingAssembly ?? Assembly.GetEntryAssembly(); RoslynCompilationService compilationService = new RoslynCompilationService(referenceManager, assembly);
This will cause null value exception if you run your code in unit test and cross projects.
Well, that sounds pretty complicated but glad you got to the bottom of it. Let me know when build
RazorLight 2.0.0-rc.4
is ready and I’ll check it out.