RazorLight: Project cannot find template with key ForgotPassword.cshtml.
liamkavfc opened this issue · 1 comments
Describe the bug
I am running into the error that is mentioned in the title.
When I list my embedded files, the file in question is the only one in the list, but the error still remains.
`string[] files = typeof(QueueTrigger).Assembly.GetManifestResourceNames();
foreach (string file in files)
{
Console.WriteLine(file);
}`
`var engine = new RazorLightEngineBuilder()
.UseEmbeddedResourcesProject(typeof(QueueTrigger).Assembly, "EmailFunction.EmailTemplates")
.UseMemoryCachingProvider()
.Build();
var rendered = await engine.CompileRenderAsync("ForgotPassword", messageDto);`
System.Private.CoreLib: Exception while executing function: QueueTrigger. RazorLight: Project can not find template with key ForgotPassword.cshtml.
To Reproduce
Steps to reproduce the behavior:
Follow README.md steps 'Embedded Resource'
Expected behavior
I would expect the error to not be there after following the README
Information (please complete the following information):
- OS: Windows 11
- Platform: .NET 6
- RazorLight version: 3.0.2
- Are you using the OFFICIAL RazorLight package? Yes
- Visual Studio version: Visual Studio Community 17.3.6
Additional context
I am implementing this in an Azure function. I have read the README.md section on this and have jumped this hurdle, I feel like the key not found is the last step.
Fixed this issue!
var engine = new RazorLightEngineBuilder()
.UseEmbeddedResourcesProject(typeof(QueueTrigger).Assembly)
.SetOperatingAssembly(typeof(QueueTrigger).Assembly)
.UseMemoryCachingProvider()
.Build();
var rendered = await engine.CompileRenderAsync("EmailTemplates.ForgotPassword", messageDto);
Adding SetOperatingAssembly()
fixed it! 👍