Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Website upgraded to MVC 5 has missing DisplayMode property on ControllerContext

I recently updated my website to MVC 5. It ran well on my dev machine. when I moved to staging on shared hosting supporting .Net 4.0 where my MVC 4 site worked just fine. After deployment I received following exception.

 Method not found: 'System.Web.WebPages.IDisplayMode
 System.Web.Mvc.ControllerContext.get_DisplayMode()'.

I tried few things to troubleshoot issue but none helped.

  1. I Checked documentation if DisplayMode is a property added only in MVC 5. I was wrong. It was there in MVC 4 also as checked in msdn documentation.
  2. strange thing on MSDN, When i checked for System.Web.Mvc.ControllerContext type it pointed me here. thing to notice here is when you change Framework version to 4.0 it is not showing same property on ControllerContext. It felt kind of weird.

My assumption is that .Net 4.5 & MVC 5.0 combination may not have this method.

My Assembly bindings.

 <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages.Razor"
        publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>        
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
  </dependentAssembly>
like image 773
Chintan Shah Avatar asked Dec 16 '22 04:12

Chintan Shah


2 Answers

I faced the same issue while upgrading to MVC 5.

This was solved by removing Microsoft.Web.Mvc.FixedDisplayModes.dll. The dll is an old legacy fix for MVC4 and it can safely be removed when working with MVC5.

I got this solution from here: http://larre.fixstar.net/2014/10/sitecore-mvc-error-idisplaymode/

like image 165
Sankar Avatar answered Dec 17 '22 16:12

Sankar


I would make sure that you followed all the steps in order to upgrade your project to MVC 5. Also, check the following:

  1. You have the proper assembly binding redirects in your web.config.
  2. The web.config in your views folder is pointing at the correct version of the System.Web.WebPages assembly (should be 3.0.0.0).
  3. You have set the new MVC 5 items (System.Web.WebPages, System.Web.Mvc, System.Web.Helpers,etc) to Copy Local = True in your project.

Also, I believe MVC5 is .NET 4.5, not 4.0 (but I cannot find anywhere that lists the required .NET versions). If your host is .NET 4.0, this could also be an issue.

It could be that your shared hosting does not have these MVC 5 items installed in the GAC on the server. As a result, while MVC 4 worked, MVC 5 is failing because of bad assembly loads/matches.

like image 29
Tommy Avatar answered Dec 17 '22 16:12

Tommy