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=4.0.0.0, 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 L.
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:
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
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