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

error while using .UseEmbeddedResourcesProject(System.Reflection.Assembly.GetEntryAssembly()) #474

Closed passronny closed 1 year ago

passronny commented 2 years ago

hi I am using razorlight in .net core2.2 MVC web project, i have registered the services of razorlight in the Startup.cs class as shown below

` var engine = new RazorLightEngineBuilder() .UseEmbeddedResourcesProject(System.Reflection.Assembly.GetEntryAssembly()) //.UseFileSystemProject($"{RootPath}\Views") .EnableDebugMode(true) .UseMemoryCachingProvider() .Build();

        services.AddSingleton<IRazorLightEngine>(engine); `

i have also created a generic class that converts my views to string , one of the methods is below

` public async Task GenerateNotificationContent(string messageBody, string pathToView) { var model = new CustomEmailMessageModel { MessageBody = messageBody
};

        return await razorLightEngine.CompileRenderAsync($"{pathToView}", model);
    } `

the views that i want are in the Views folder of the project, so when calling the above method i provide the path to the view that i want e.g Views/Subfolder/View but im getting the below error

RazorLightProjectItem of type RazorLight.Razor.EmbeddedRazorProjectItem with key Views/Subfolder/view.cshtml could not be found by the RazorLightProject of type RazorLight.Razor.EmbeddedRazorProject and does not exist in dynamic templates. See the "KnownDynamicTemplateKeys" and "KnownProjectTemplateKeys" properties for known template keys.

what am i doing wrong

jzabroski commented 2 years ago

Did you read the error message? It says: See the "KnownDynamicTemplateKeys" and "KnownProjectTemplateKeys" properties for known template keys.

Put a breakpoint and check that please.

vijkumarsharma commented 1 year ago

@passronny @jzabroski is this issue resolved? I am also facing the same issue

jzabroski commented 1 year ago

@vijkumarsharma I will repeat:

Did you read the error message? It says: See the "KnownDynamicTemplateKeys" and "KnownProjectTemplateKeys" properties for known template keys.

Put a breakpoint and check that please.

Your last reply in #250 was vague and non-constructive. I don't know what you see, and you made no efforts to describe what you see when you put a breakpoint. Describing something as "not fruitful" and "the same issue" is not descriptive. At most, you can conclude you have the same error message, not the same issue.

JMcConahie commented 1 year ago

Can you verify that you set the "Build Action" to "Embedded resource" in the properties of the .cshtml files? I had a similar issue and realized I forgot this step.

jzabroski commented 1 year ago

Close this as it seems to be something people report when they don't read the FAQ or exception message