Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nustache View Engine ArrayTypeMismatchException

Trying to use Nustache to share client and server mustache templates, but Nustache is just not playing nicely with my app. I used the code straight out of their MVC application example in the source code but am getting an error every time I try to set or add the view engine. Here's a code snippet (from an action method, I've also tried adding the view engine globally in global.asax and had the same error):

ViewResult viewResult = View(new { test = "Jawesome" });

viewResult.ViewEngineCollection = new ViewEngineCollection
                                  {
                                      new NustacheViewEngine()
                                  };

And here's the error:

[ArrayTypeMismatchException: Attempted to access an element as a type incompatible with the array.]
   System.Collections.Generic.List`1.Insert(Int32 index, T item) +62
   MyController.Index() in C:\src\projects\myproject\myproject.Web\Controllers\MyController.cs:83
   lambda_method(Closure , ControllerBase , Object[] ) +79
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +264
   ...
like image 614
mmurch Avatar asked Nov 14 '22 11:11

mmurch


1 Answers

I am using MVC4 with Nustache and I was having the exact same issue. It took me a while to figure out the issue and I couldn't find any solutions on the web so I thought I would post my solution in hopes of helping someone else.

The issue was the Nustache.Mvc3 project was referencing System.Web and System.Web.Mvc from MVC3 so I had to update them to use MVC4. To do that: 1. In Visual Studio, right-click Nustache.Mvc3 project and select Properties 2. In the Applicaiton tab, change Target Framework to .Net Framework 4.5 3. Go back to Solution Explorer, delete System.Web and System.Web.Mvc under References in Nustache.Mv3 4. Right-click References and Add version 4.0 for both System.Web and System.Web.Mvc

like image 172
Joe Avatar answered Nov 16 '22 03:11

Joe