razorrazorengine.net-core-3.1

Could not load type 'Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine'


I am using RazorEngine.NetCore in .Net Core 3.1 and when I run below code

string template = "Hello @Model.Name!";
        var result = Engine
            .Razor
            .RunCompile(template,
                "templateKey",
                null,
                new
                {
                    Name = "World"
                });

I am getting the following error

'Could not load type 'Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine' from assembly 'Microsoft.AspNetCore.Razor.Language, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.'

Solution

  • What version of RazorEngine.NetCore are you using? If you are using "2.2.6" or below, change it to "3.1.0".