Application migration to MVC4 - MVC3/4 conflict

Apr 9, 2013 at 2:57 PM
Edited Apr 9, 2013 at 3:03 PM
Hello All,

I have to migrate a solution from MVC3 to MVC4/.Net 4.5. Everything was working with pre-compiled views under MVC3, but our new dev standard is MVC4.

The migration effort consisted of creating a blank MVC4 main project and spoon feeding the various controllers/models/views files in. :P Everything compiles and works fine with the built-in controllers.

For the pre-compiled views project, I created a class library project and, again, manually created the MVC-like folders and copied in the files. I re-added the nuget package to the solution with the RazorGenerator custom build tool and attached it to the view file. All compiles well.

However, it appears that since RazorGenerator.Mvc.dll was created against MVC3, it can't add the view engine in the PostApplicationStart because of a conflict in ViewEngines.Engines defined in two places. I searched thru the entire solution and no references to MVC3 anywhere.

So: can I use razor generator with MVC4? Or should I be doing a binding redirect from MVC3 to MVC4 assemblies (and how/where should this be done?). I've seen various posts that reference MVC4, so this should be possible, right? Looking at my packages, I have WebActivatorEx V2.0.0 installed, which is different than what is referenced in the other posts.,

Thanks for the effort on this great addin!

Apr 9, 2013 at 4:15 PM
It's strange that you're running into this, because MVC4 applications already include all the relevant binding redirects in web.config. e.g.
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="" newVersion="" />
Can you check whether you have those?
Apr 9, 2013 at 4:41 PM
It appears my web.config does not have the bindingRedirects. Looking into why, I found out a collegue 'cleaned up' the web.config thinking we didn't need the redirects since MVC4 is the official standard. I restored the redirects and all is well now. Thanks for pointing me to where to start looking.
Apr 9, 2013 at 4:55 PM
Ah yes, the classic "this can't possibly be of any use" syndrom :)

The entry is crucial, as it allow any library built against MVC 3 (or earlier) to be used in your MVC 4 app.