I encountered this problem when moving from an old machine to a new machine. I vaguely recall having this problem once before, but it was such a long time ago I just don’t remember. However I encountered this problem all over again now recently and have been battling with it for a while. This is a very frustrating problem and I have to place blame on Microsoft for this one because this is a small instance of DLL hell. I will explain why below.
The really annoying problem
You attempt to run a site on IIS and you are immediately met with the yellow screen of death with one of the following errors:
- Could not load file or assembly ‘System.Web.WebPages.Deployment’
- Could not load file or assembly ‘System.Web.WebPages’
You check your project to make sure those references are there and to your disgruntled disbelief, yes – yes they are – they are staring you right in the face… Oh boy one of those problems…
I don’t have time to read all of this where is the answer?
Go to the very bottom of this post. Run the installers mentioned.
Where did the DLLs even come from?
At first glance you see that these DLLs were already present more than likely and have come over with all of the other MVC related DLLs via NuGet. Weird – you check your references and even attempt to reinstall them. No good.
Work around but not a true fix
Even though you never had to do this before, you can add an explicit reference to the “System.Web.WebPages.Deployment” dll in your Web.config like so:
<assemblyIdentity name="System.Web.WebPages.Deployment" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="184.108.40.206-220.127.116.11" newVersion="18.104.22.168" />
However this is just covering up the real issue.
Long forgotten WebMatrix
I recall a very long time ago installing MVC as a separate installation. I know that sounds weird, but I remembered doing it, but after several more Visual Studio updates this was no longer required – or so I thought. This is where Microsoft screwed up. There was an installer named “WebMatrix” installer which was to get you started with MVC. There were two installations that I could find:
|Installer name||URL||DLL Version|
This will install the following dlls into the GAC MSIL (C:\windows\Microsoft.NET\assembly\GAC_MSIL):
All of these DLLS have the same public key token: 31bf3856ad364e35
The incredibly stupid fix
Therefore, even though Microsoft says right on their page about the WebMatrix to discontinue using it, you can’t because you require it to put the necessary DLLs into the GAC. Woopsie.
So ultimately to fix this problem just install the WebMatrix tools. I installed both versions just to be sure, but I really only needed version 22.214.171.124.