toddams/RazorLight

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

passronny opened this issue · 5 comments

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

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.

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

@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.

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.

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