Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
passronny opened this issue Mar 23, 2022 · 5 comments

Comments

@passronny
Copy link

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
Copy link
Collaborator

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
Copy link

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

@jzabroski
Copy link
Collaborator

@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
Copy link

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants