Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

546
Visualizações
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 Respostas
Responde à pergunta

0

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

almost 4 years ago · john obasi Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda