Error when using older ASP.NET MVC assemblies

Damir Dobric Posts

Next talks:



Follow me on Twitter: #ddobric




When migrating projects form older ASP.NET MVC version (i.e: MVC 4) you may experience some issues. Before you start migration I would highly recommend following article.
It very nicely describes how to perform all required steps.

Unfortunately the clock of the real world projects ticks in a different lifecycle interval than MVC. We usually build applications which have much longer live cycle than more or less any technology which lives on top of framework like .NET. ASP.NET MVC falls also in this category.

Here is the problem. Start application and nothing will work. You will simply experience Bad Request when trying to invoke some WebApi method. If you take a look in Event Log you might find following:

Exception information:
    Exception type: HttpException
    Exception message: Could not load file or assembly 'System.Web.Http, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app)
   at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers)
   at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context)
   at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context)
   at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)

This exception is one of many which can be thrown in a chain. It depends on number of old assemblies which your web application might use.
Now you can ask yourself: “How this can happen if I migrated all correctly as describe in the article above”?

The answer is very simple. If you are member of big project, you might have migrated your application, but there is probably some team which deliver component which is not migrated

That means your migrated application depends on MVC5 assembly set, but old(er) components will depend on MVC4 assembly set.

You need to do following. Append assembly redirection for all assemblies which fail in binding process:


        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" />

        <bindingRedirect oldVersion="" newVersion="" />




        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" />

        <bindingRedirect oldVersion="" newVersion="" />


The exception above was caused by Web.Http, but after I fixed this assembly Http.Formating was the next problem, and so on.

Posted Dec 27 2013, 02:06 PM by Damir Dobric
Filed under: , , is a .Net Community Blog powered by daenet GmbH.