Open gswartz777 opened 1 year ago
Bumping in hopes someone has an idea.
I'm getting the same error in a .NET 7.0 project.
Here is the message: `RazorLight.Compilation.TemplateCompilationException: 'Failed to compile generated Razor template:
Hi,
I have the same error with my cshtml in a .NET standard 2.0 class library used by a .NET 4.6.2 console application. Any idea ?
Regards Sybaris
Here the code of my Console Application (.NET 4.6.2) :
internal class Program
{
static void Main(string[] args)
{
var engine = new RazorLightEngineBuilder()
.UseEmbeddedResourcesProject(typeof(Person).Assembly, "ClassLibrary3")
.SetOperatingAssembly(typeof(Person).Assembly)
.UseMemoryCachingProvider()
.Build();
var model = new Person() { Name = "Jean" };
string html = engine.CompileRenderAsync("report", model).Result;
Console.WriteLine(html);
}
}
And now the code of my ClassLibrary .NET 2.0 Standard : My model :
using System;
namespace ClassLibrary3
{
public class Person
{
public string Name { get; set; }
}
}
And my report.cshtml :
@model Person
@using System.Collections.Generic
@using RazorLight
@using ClassLibrary3
@inherits TemplatePage<Person>
Bonjour @Model.Name
And the result is :
TemplateCompilationException: Failed to compile generated Razor template:
See CompilationErrors for detailed information
Note that :
<PreserveCompilationContext>true</PreserveCompilationContext>
Hi,
I found the solution for my part :
I change this line of code
.SetOperatingAssembly(typeof(Person).Assembly)
by
.SetOperatingAssembly(typeof(Program).Assembly)
And it's solves my problem. Regards Sybaris
Describe the bug We are trying to migrate a .NET Framework solution to .Net core/.Net 6. In doing so, our infrastructure projects in the solution that power our 2 web application projects have been converted to .Net Standard 2 so we can have the updates live while migrating the web apps. In one of the .Net Standard 2 projects, we need to compile .cshtml views with models so I tried to use RazorLight. I've had to install a number of nuget packages in the web app but have finally gotten past all of those exceptions and now I'm at, what I hope is, the last of the exceptions. When I try to use the CompileRenderStringAsync as below I get the error "The type or namespace name 'Razor' does not exist in the namespace 'RazorLight'".
To Reproduce Create a .Net Standard 2 library referencing RazorLight. Create a .Net Frameworks 4.7.2 web app and reference the first library app. Create a call through a button or something in the web app that tries to call the .Net Standard's implementation of RazorLight.
Expected behavior Expecting... or hoping, to be able to compile .cshtml views.
Information (please complete the following information):