Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

545
Views
RazorLight RazorLight.TemplateNotFoundException: Project can not find template with key

I am trying to generate HTML based on a .cshtml file, which is embedded:

<EmbeddedResource Include="Templates\ReportTemplate.cshtml" />

However, from RazorLight I always get the following Exception:

 RazorLight.TemplateNotFoundException: Project can not find template with key My.Namespace.Application.Templates.ReportTemplate.cshtml
   at RazorLight.Compilation.RazorTemplateCompiler.CreateRuntimeCompilationWorkItem(String templateKey)
   at RazorLight.Compilation.RazorTemplateCompiler.OnCacheMissAsync(String templateKey)
   at RazorLight.Compilation.RazorTemplateCompiler.CompileAsync(String templateKey)
   at RazorLight.EngineHandler.CompileTemplateAsync(String key)
   at RazorLight.EngineHandler.CompileRenderAsync[T](String key, T model, ExpandoObject viewBag)

But when I check the embedded resources, I can clearly see the embedded resource :

string[] files = Assembly.GetExecutingAssembly().GetManifestResourceNames();

files contains: My.Namespace.Application.Templates.ReportTemplate.cshtml

Here is my code to generate the PDF:

private async Task<string> RenderRazorTemplate(string key, Type viewModelType, object viewModel)
    {

        string[] files = Assembly.GetExecutingAssembly().GetManifestResourceNames();
        var engine = new RazorLightEngineBuilder()
            .UseEmbeddedResourcesProject(Assembly
            .GetExecutingAssembly()) // Use the Executing Assembly as project that embeds the .cshtml templates
            .SetOperatingAssembly(viewModelType.Assembly) // Without this, you'll get a Exception saying that the Assembly can't find the AntiForgery.dll
            .UseMemoryCachingProvider()
            .Build();
        
        return await engine.CompileRenderAsync(key, viewModel);
    }

My parameters are: Key: My.Namespace.Application.Templates.ReportTemplate.cshtml

I am using RazorLight.NetCore3 Version 3.0.2

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

hello, did you manage to find an a solution? i'm facing same issue

almost 4 years ago · john obasi Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!