Q:

Why won't my MVC4 HandleErrorAttribute work?

I'm converting an MVC3 web project to MVC4. I created a ElmahHandleErrorAttribute that inherits from HandleErrorAttribute that worked fine in MVC3 and also works fine on my local dev machine, but it throws the following exception in the test environment...
[InvalidOperationException: The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.]
   System.Web.Mvc.GlobalFilterCollection.ValidateFilterInstance(Object instance) +110
   System.Web.Mvc.GlobalFilterCollection.AddInternal(Object filter, Nullable`1 order) +17
   System.Web.Mvc.GlobalFilterCollection.Add(Object filter) +12
   Home2Me.MvcApplication.RegisterGlobalFilters(GlobalFilterCollection filters) in c:\###\Home2Me\Global.asax.cs:16
   Home2Me.MvcApplication.Application_Start() in c:\###\Home2Me\Global.asax.cs:118

[HttpException (0x80004005): The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.]
   System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9249709
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253

[HttpException (0x80004005): The given filter instance must implement one or more of the following filter interfaces: IAuthorizationFilter, IActionFilter, IResultFilter, IExceptionFilter.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9164336
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256

There isn't really anything special about the class. It's pretty close to the standard one for Elmah.
public class ElmahHandleErrorAttribute : System.Web.Mvc.HandleErrorAttribute
{

    /// <summary>
    /// Called when an exception occurs.
    /// </summary>
    /// <param name="context"></param>
    public override void OnException(ExceptionContext context)
    {
        base.OnException(context);
        if (!context.ExceptionHandled) return; // if unhandled, will be logged anyhow
        var e = context.Exception;
        HandleException(e);
    }

... (code snipped for brevity) ...

}

And here is the code that registers the filter in Global.asax.cs...
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new ElmahHandleErrorAttribute());
}

The filter is defined in a separate assembly that is also updated to MVC4. I have multiple projects that use this filter. One of them works fine in the test environment, and another has this same exact issue.
Any ideas on what might be wrong? I'm fairly confident that all the MVC3 references have been updated correctly in the project, including the web.config files in both the root and views directory. It does work locally and I uninstalled MVC3 and deleted all the "extra" MVC3 dlls lying around.  

A:

I believe I found an answer. I added a runtime section in the root web.config file to convert MVC3 references to MVC4. 
<configuration>
    ... (snipped for brevity) ...
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

I would rather fix whatever it is that is referencing MVC3, but I can't figure out what that might be. This will have to be a good enough answer for now.

