Razor Engine not working in ASP.net 5 MVC 6
Asked Answered
B

1

9

I am trying to migrate some existing code from MVC5 to MVC6 and I am having difficulty with this particular code:

 Engine.Razor.RunCompile(File.ReadAllText(emailTemplatePath), "emailTemplateKey", typeof (EmailViewModel), emailViewModel);

I am receiving the following runtime error:

MissingMethodException: Method not found: "Void Microsoft.AspNet.Razor.CodeGenerators.GeneratedClassContext.set_ResolveUrlMethodName(System.String)". in RazorEngine.Compilation.CompilerServiceBase.CreateHost(Type templateType, Type modelType, String className)

The original code I was using in MVC5 was taken from here. If there is no way of converting the above code to work with MVC6 what is another elegant way of doing email templates?

Bible answered 27/1, 2016 at 7:54 Comment(2)
Do not mention other posts that describe a problem similar to yours, without explaining your situation. Also post your code, and the error messages you get. Please take a look at stackoverflow.com/help/how-to-ask and then edit your questionPaper
you want to migrate from mvc5 to mvc6 or create a email templateUnreserve
P
2

Apparently there has been a change in GeneratedClassContext class - the property ResolveUrlMethodName does not exist anymore, hence the MissingMethodException. Looks like ParserContext class has changed too, since accessing OnError event handler throws the same exception.

In fact it is the setter of the missing property missing (pardon the expression!), which, being a method, causes the exception. Absolutely accurate but somewhat misleading, unless you recall this.

Quite a similar question (and a good answer with alternative solution!) here: RazorEngine and MVC 6 beta 7.

Pacification answered 3/2, 2016 at 6:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.