RazorEngine icon indicating copy to clipboard operation
RazorEngine copied to clipboard

Throw Error in .NetCore 3.1

Open texyh opened this issue 5 years ago • 7 comments

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

texyh avatar Feb 18 '20 08:02 texyh

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 ?

nicklas669 avatar Mar 13 '20 11:03 nicklas669

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

standamikes avatar Mar 13 '20 13:03 standamikes

Same +

SemeniakoTaras avatar Apr 01 '20 10:04 SemeniakoTaras

Same here

fomekh avatar May 12 '20 14:05 fomekh

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.

Dunkhan avatar Jun 08 '20 14:06 Dunkhan

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

texyh avatar Jul 03 '20 09:07 texyh

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

folsomfisher avatar Jun 10 '22 22:06 folsomfisher