Friday, May 25, 2012

Could not load type 'System.Web.WebPages.DisplayModes' from assembly 'System.Web.WebPages, Version=2.0.0.0

I got this annoying error recently on my ASP.NET MVC 4 Beta project and didn't find any real solutions/explanations on Google. So after investigating it here are my findings.

The basic problem is that there is a mixup between MVC 4 Developer Preview and MVC 4 Beta .dlls in the project. To see which version you have right click the .dll file in Windows Explorer and choose Properties->Details. Look for  'File Version' :

  • MVC 4 Developer Preview is version 4.0.10906.0
  • MVC 4 Beta is version 4.0.20126.16343


Make sure all says the MVC 4 beta version number (replace the .dlls from a fresh MVC 4 Beta project if necessary) for these files:

  • System.Web.Mvc
  • System.Web.WebPages
  • System.Web.Razor
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor

It should then work.

(Technical: It is actually the older version of System.Web.Mvc.dll that tries to use a removed/changed item in the newer System.Dll.WebPages library. DisplayMode have been replaced with DisplayModeProvider)

3 comments:

  1. Thanks TK - after spending hours trawling through search results that didn't help, this fixed it for me!

    I have no idea how I ended up with incompatible versions of the above DLLs in the bin directory (the problem arose when a DLL makes a call to a method in an incompatible DLL - it wasn't a call from our own code - which made it doubly difficult to track down) - but if anyone else finds themselves here after an exhausting search elsewhere, here's what worked very quickly for me: just remove the above DLLs from the project bin directory (using "Clean" in Visual Studio didn't seem to do this for some reason), then rebuild the project: the above files don't need to be in the bin directory - the GAC seems to be able to find the correct versions all on its own.

    ReplyDelete
  2. Thanks for your comment. I think the big problem is (if I recall correct) that the two .dlls have the same version number so Visual Studio just grabs the first one it finds.

    The problem should go away now that the final #4 is released, but yeah it was quite a headscratcher for a while.

    ReplyDelete
  3. In my case I updated from MVC 4 Dev Preview to MVC 4 using NuGet and fixed the issue. Thanks!

    ReplyDelete