Antaris/RazorEngine

Throw Error in .NetCore 3.1

Opened this issue · 7 comments

texyh commented

Hey guys
please i have a little question
i am using RazorEngine.NetCore in .Net Core 3.1 and when i run Engine.Razor.Compile(key); i get the following error
Could not load type Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine' from assembly 'Microsoft.AspNetCore.Razor.Language, Version=3.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60

I get the same.

System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine' from assembly 'Microsoft.AspNetCore.Razor.Language, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
   at RazorEngine.Compilation.CompilerServiceBase.GetGeneratorResult(IEnumerable`1 namespaces, TypeContext context)
   at RazorEngine.Compilation.CompilerServiceBase.GetCodeCompileUnit(TypeContext context)
   at RazorEngine.Roslyn.CSharp.RoslynCompilerServiceBase.CompileType(TypeContext context)
   at RazorEngine.Templating.RazorEngineCore.CreateTemplateType(ITemplateSource razorTemplate, Type modelType)
   at RazorEngine.Templating.RazorEngineCore.Compile(ITemplateKey key, Type modelType)
   at RazorEngine.Templating.RazorEngineService.CompileAndCacheInternal(ITemplateKey key, Type modelType)
   at RazorEngine.Templating.RazorEngineService.GetCompiledTemplate(ITemplateKey key, Type modelType, Boolean compileOnCacheMiss)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.DynamicWrapperService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, String templateSource, String name, Type modelType, Object model, DynamicViewBag viewBag)

Did you find any solution @texyh ?

Same here, it would be great to add support for .net core 3+, please

Same +

Same here

So I managed to resolve this in my project. The issue is that the newest version of the lib AspNetCore.Razore.Language does not have the templating class. If any project in your solution uses the newer version of this dll the old version will not be copied into the output directory. You need to search through all your packages and make sure that razor version 2.2 is the newest one installed everywhere. If other parts of your project/solution require a newer version than 2.2 then you will not be able to use RazorEngine and will have to try one of the alternatives.

texyh commented

i think this project https://github.com/fouadmess/RazorEngine support 3.1

I fixed it by uninstalling Microsoft.VisualStudio.Web.CodeGeneration.Design (suggested by someone else)
Uninstall-Package Microsoft.VisualStudio.Web.CodeGeneration.Design