Antaris / RazorEngine

Open source templating engine based on Microsoft's Razor parsing engine
http://antaris.github.io/RazorEngine
Other
2.13k stars 578 forks source link

Throw Error in .NetCore 3.1 #564

Open texyh opened 4 years ago

texyh commented 4 years ago

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

nicklas669 commented 4 years ago

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 ?

standamikes commented 4 years ago

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

SemeniakoTaras commented 4 years ago

Same +

fomekh commented 4 years ago

Same here

Dunkhan commented 4 years ago

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 4 years ago

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

folsomfisher commented 2 years ago

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