Search code examples
.netmonorazorengine

using RazorEngine v3 on Mono v2.10


Is there a way to use RazorEngine v3 on Mono v2.10?

I get the following error when trying to parse a template.

TypeLoadException: A type load exception has occurred.
  at RazorEngine.Templating.TemplateService.CreateTemplateType (System.String razorTemplate, System.Type modelType) [0x00000] in <filename unknown>:0 
  at RazorEngine.Templating.TemplateService.CreateTemplate[<>f__AnonymousType0`2] (System.String razorTemplate, .<>f__AnonymousType0`2 model) [0x00000] in <filename unknown>:0 
  at RazorEngine.Templating.TemplateService.Parse[<>f__AnonymousType0`2] (System.String razorTemplate, .<>f__AnonymousType0`2 model) [0x00000] in <filename unknown>:0 
  at RazorEngine.Razor.Parse[<>f__AnonymousType0`2] (System.String razorTemplate, .<>f__AnonymousType0`2 model) [0x00000] in <filename unknown>:0 

Solution

  • TL/DR: Update to Mono 3.x.

    Long story: at the time Mono 2.10.x was released, Microsoft had not fully released the ASP.NET stack as open source (Razor was one of the components that was still closed source).

    Recently Microsoft finally opensourced the full stack, and Mono has included it in their tree, however this happened after 2.10 was released and will not be backported.

    Even longer story: http://tirania.org/blog/archive/2012/Mar-28.html