Getting Spark View Engine to work with ASP.NET MVC

Comments 0

Share to social media

Method not found: ‘Void System.Web.Mvc.ViewContext..ctor(System.Web.Mvc.ControllerContext, System.Web.Mvc.IView, System.Web.Mvc.ViewDataDictionary, System.Web.Mvc.TempDataDictionary)’

I am finding that there are several complaints about getting Spark View Engine to work with ASP.NET MVC.  I had to tweak the Spark View Engine code base to get things running again.

I had to download the spark view engine source code (http://sparkviewengine.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27600).  Once I did that I went through each of the projects that had a reference to the 1.0 version of System.Web.Mvc assembly and updated to reference to point to System.Web.Mvc 2.0.  From there you can build the solution (in visual studio) and you will find that a whole bunch of tests start to fail.  You can attempt to fix them (by adding the additional TextWriter parameter you will find is now needed).  You will also see that the SparkView.cs file complains about a missing parameter.  In the Render method (line 100 of the source code I downloaded) I had to update the instantiation of the wrappedViewContext to look like this (add writer to the end of the list of parameters):

    public void Render(ViewContext viewContext, TextWriter writer)
    {
        var wrappedHttpContext = new HttpContextWrapper(viewContext.HttpContext, this);
        var wrappedViewContext = new ViewContext(
            new ControllerContext(wrappedHttpContext, viewContext.RouteData, viewContext.Controller),
            viewContext.View,
            viewContext.ViewData,
            viewContext.TempData,
            writer); //  <– add the writer to the end of the list of parameters
        …
    }

Once the code is updated you can run the build.cmd script that is in the root of the source you downloaded.  The build process will create a zip file in the build/dist folder.  Take those new dll’s and add them to your website.  Things should work once again.

Load comments

About the author

Andrew Siemer's contributions