Umbraco

Getting a System.Web.Http.ApiController error?

[Updated Oct. 17th, see below]

We've had some reports of sudden errors on Umbraco sites that were absolutely fine the day before and believe we've pinpointed it to Windows a security update that rolled out to Windows Update starting Tuesday this week.

The symptom is that you'll get an error saying:

The type 'System.Web.Http.ApiController' is defined in an assembly that is not referenced.
You must add a reference to assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'
.


The fix for this should be fairly easy: in your web.config find the compilation\assemblies section and add the System.Web.Http assembly there under System.Net.Http:

<add assembly="System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />


This seems to help for most people running into this problem. Another thing that might help, if you get errors compiling your code, try referencing System.Web.Http version 4 and setting the build action to "copy local".

We'll update this blog post as more information becomes available. 

Update: In addition to the update above, we of course take over Microsoft's recommendation to update to System.Web.Mvc 4.0.0.1. The easiest way to do this is to copy the new version of the dll into your bin folder. You'll also need to update your assemblyBindings if you have one for System.Web.Mvc (else we recommend you add one). So in your web.config the runtime\assemblyBinding section should have the following binding:

<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
</dependentAssembly>


Of course if you've installed Umbraco through NuGet, you simply update using the following command in your package manager console: 

Update-Package Microsoft.AspNet.Mvc -Version 4.0.40804


After doing that and building the project, the assemblyBinding will have updated automatically.

Umbraco 6.0.0 and higher ship with MVC4. If you're running an older version of Umbraco with MVC3 in it, the instructions are similar, you need to update to MVC 3 version: 3.0.50813.1 and do an assembly redirect to the new version 3.0.0.1.