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?

Cool Breeze
  • 1,289
  • 11
  • 34
  • 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 http://stackoverflow.com/help/how-to-ask and then edit your question – Manos Pasgiannis Feb 01 '16 at 09:47
  • you want to migrate from mvc5 to mvc6 or create a email template – anand Feb 04 '16 at 13:23

1 Answers1

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.

Community
  • 1
  • 1
Alexander Christov
  • 9,625
  • 7
  • 43
  • 58