toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.5k stars 259 forks source link

Make sure PreserveCompilationContext is set to true #537

Open JozefGula opened 7 months ago

JozefGula commented 7 months ago

Hello, can someone help me?

I have an ASP Net 7.0 project with RazorLight 2.3.1. I added "PreserveCompilationContext" to my *.csproj. However, I keep getting this error:

"Can't load metadata reference from the entry assembly. Make sure PreserveCompilationContext is set to true in *.csproj file"

I tried various combinations with PreserveCompilationContext but without success. Nothing in the FAQ solves my problem.

var engine = new RazorLightEngineBuilder()
    .UseEmbeddedResourcesProject(typeof(Program).Assembly, typeof(Program).Namespace)
    .UseMemoryCachingProvider()
    .SetOperatingAssembly(typeof(Program).Assembly)
    .EnableDebugMode(true)
    .Build();

return await engine.CompileRenderAsync("Views.EmailTemplates.Email", model);

Any ideas? Thank you very much