title: ASP MVC 5: The assembly with display name 'System.Web.Http' failed to load exception, then runs seamlessly
body: <p>I am getting the following exception just when starting my MVC application, I am not even referencing that assembly (yes I know other assemblies what I reference may reference it.)</p>
  
  <p>"The assembly with display name 'System.Web.Http' failed to load"</p>
  
  <pre><code>public class MvcApplication : HttpApplication
  {
      protected void Application_Start()
      {
          // I am getting the exception here:
          AreaRegistration.RegisterAllAreas();
          /...
      }
  }
  </code></pre>
  
  <p>The complete text of the exception is the following:</p>
  
  <pre><code>The assembly with display name 'System.Web.Http' failed to load in the 'Load' 
  binding context of the AppDomain with ID 2. The cause of the failure was:   
  System.IO.FileNotFoundException: Could not load file or assembly 
  'System.Web.Http, Version=5.0.0.0, Culture=neutral, 
  PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot 
  find the file specified.
  </code></pre>
  
  <p>After skipping this exception everything seems to be working normally still it is not a comfortable feeling do not know what's going on.</p>
  
  <p>To answer the comment, here is my nuget:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;packages&gt;
    &lt;package id="Antlr" version="3.5.0.2" targetFramework="net451" /&gt;
    &lt;package id="AutoMapper" version="3.3.1" targetFramework="net451" /&gt;
    &lt;package id="bootstrap" version="3.3.4" targetFramework="net451" /&gt;
    &lt;package id="EntityFramework" version="6.1.3" targetFramework="net451" /&gt;
    &lt;package id="fasterflect" version="2.1.3" targetFramework="net451" /&gt;
    &lt;package id="jQuery" version="2.1.4" targetFramework="net451" /&gt;
    &lt;package id="jquery.TypeScript.DefinitelyTyped" version="2.2.6" targetFramework="net451" /&gt;
    &lt;package id="jQuery.Validation" version="1.13.1" targetFramework="net451" /&gt;
    &lt;package id="log4net" version="2.0.3" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.Identity.EntityFramework" version="2.2.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.Identity.Owin" version="2.2.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.Owin" version="3.0.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.Owin.Security" version="3.0.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.Owin.Security.Cookies" version="3.0.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.Owin.Security.Facebook" version="3.0.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.Owin.Security.Google" version="3.0.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.Owin.Security.MicrosoftAccount" version="3.0.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.Owin.Security.OAuth" version="3.0.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.Owin.Security.Twitter" version="3.0.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net451" /&gt;
    &lt;package id="Moment.js" version="2.10.3" targetFramework="net451" /&gt;
    &lt;package id="Moment.Timezone.js" version="0.4.0" targetFramework="net451" /&gt;
    &lt;package id="moment.TypeScript.DefinitelyTyped" version="1.0.6" targetFramework="net451" /&gt;
    &lt;package id="moment-timezone.TypeScript.DefinitelyTyped" version="0.0.5" targetFramework="net451" /&gt;
    &lt;package id="Newtonsoft.Json" version="7.0.1" targetFramework="net451" /&gt;
    &lt;package id="Ninject" version="3.2.2.0" targetFramework="net451" /&gt;
    &lt;package id="Ninject.MVC5" version="3.2.1.0" targetFramework="net451" /&gt;
    &lt;package id="Ninject.Web.Common" version="3.2.3.0" targetFramework="net451" /&gt;
    &lt;package id="Ninject.Web.Common.WebHost" version="3.2.3.0" targetFramework="net451" /&gt;
    &lt;package id="NodaTime" version="1.3.1" targetFramework="net451" /&gt;
    &lt;package id="Owin" version="1.0" targetFramework="net451" /&gt;
    &lt;package id="PayPal" version="1.5.0" targetFramework="net451" /&gt;
    &lt;package id="PluralTouch.DataAccess" version="1.2015.07.10" targetFramework="net451" /&gt;
    &lt;package id="PluralTouch.DependencyInjection" version="1.2015.07.10" targetFramework="net451" /&gt;
    &lt;package id="PluralTouch.DependencyInjection.Ninject" version="1.2015.07.10" targetFramework="net451" /&gt;
    &lt;package id="PluralTouch.Logging" version="1.2015.07.10" targetFramework="net451" /&gt;
    &lt;package id="PluralTouch.Logging.Log4Net" version="1.2015.07.10" targetFramework="net451" /&gt;
    &lt;package id="PluralTouch.Mvc" version="1.2015.07.10" targetFramework="net451" /&gt;
    &lt;package id="PluralTouch.Utils" version="1.2015.07.10" targetFramework="net451" /&gt;
    &lt;package id="Portable.Licensing" version="1.1.0" targetFramework="net451" /&gt;
    &lt;package id="T4MVC" version="3.15.4" targetFramework="net451" /&gt;
    &lt;package id="T4MVCExtensions" version="3.15.4" targetFramework="net451" /&gt;
    &lt;package id="TwitterBootstrapMVC.Eyecon.Datepicker.MVC5" version="1.0.32" targetFramework="net451" /&gt;
    &lt;package id="TwitterBootstrapMVC.Flaty.MVC5" version="1.0.29" targetFramework="net451" /&gt;
    &lt;package id="TwitterBootstrapMVC5" version="3.16.1" targetFramework="net451" /&gt;
    &lt;package id="underscore.js" version="1.8.2" targetFramework="net451" /&gt;
    &lt;package id="underscore.TypeScript.DefinitelyTyped" version="0.5.6" targetFramework="net451" /&gt;
    &lt;package id="WebActivatorEx" version="2.0.6" targetFramework="net451" /&gt;
    &lt;package id="WebGrease" version="1.6.0" targetFramework="net451" /&gt;
  &lt;/packages&gt;
  </code></pre>
  
  <p>and here is the call stack:</p>
  
  <pre><code>    mscorlib.dll!System.Reflection.RuntimeModule.GetTypes() + 0xa bytes
      mscorlib.dll!System.Reflection.Assembly.GetTypes() + 0x47 bytes
      System.Web.Mvc.dll!System.Web.Mvc.TypeCacheUtil.FilterTypesInAssemblies(System.Web.Mvc.IBuildManager buildManager = { System.Web.Mvc.BuildManagerWrapper}, System.Predicate&lt;System.Type&gt; predicate = { Method = Cannot evaluate expression because the code of the current method is optimized.}) + 0xf2 bytes
      System.Web.Mvc.dll!System.Web.Mvc.TypeCacheUtil.GetFilteredTypesFromAssemblies(string cacheName = "MVC-AreaRegistrationTypeCache.xml", System.Predicate&lt;System.Type&gt; predicate = { Method = Cannot evaluate expression because the code of the current method is optimized.}, System.Web.Mvc.IBuildManager buildManager = { System.Web.Mvc.BuildManagerWrapper }) + 0x84 bytes
      System.Web.Mvc.dll!System.Web.Mvc.AreaRegistration.RegisterAllAreas(System.Web.Routing.RouteCollection routes = Count = Cannot evaluate expression because the code of the current method is optimized., System.Web.Mvc.IBuildManager buildManager = { System.Web.Mvc.BuildManagerWrapper}, object state = null) + 0x6f bytes
      System.Web.Mvc.dll!System.Web.Mvc.AreaRegistration.RegisterAllAreas(object state = null) + 0x4c bytes
      System.Web.Mvc.dll!System.Web.Mvc.AreaRegistration.RegisterAllAreas() + 0x19 bytes  
      &gt;   ComiCalc.Web.dll!ComiCalc.Web.MvcApplication.Application_Start() Line 21 + 0x6 bytes C#
          [Native to Managed Transition]
          System.Web.dll!System.Web.HttpApplication.InvokeMethodWithAssert(System.Reflection.MethodInfo method, int paramCount, object eventSource, System.EventArgs eventArgs) + 0x81 bytes
           System.Web.dll!System.Web.HttpApplication.ProcessSpecialRequest(System.Web.HttpContext context = { System.Web.HttpContext}, System.Reflection.MethodInfo method, int paramCount, object eventSource, System.EventArgs eventArgs, System.Web.SessionState.HttpSessionState session) + 0xef bytes
      System.Web.dll!System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(System.Web.HttpContext context = { System.Web.HttpContext}, System.Web.HttpApplication app) + 0x137 bytes
      System.Web.dll!System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(System.IntPtr appContext = 52497432, System.Web.HttpContext context = { System.Web.HttpContext}, System.Reflection.MethodInfo[] handlers) + 0x77 bytes
      System.Web.dll!System.Web.HttpApplication.InitSpecial(System.Web.HttpApplicationState state, System.Reflection.MethodInfo[] handlers, System.IntPtr appContext = 52497432, System.Web.HttpContext context) + 0xad bytes
      System.Web.dll!System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(System.IntPtr appContext, System.Web.HttpContext context) + 0x161 bytes
      System.Web.dll!System.Web.Hosting.PipelineRuntime.InitializeApplication(System.IntPtr appContext = 52497432) + 0x129 bytes
      [Appdomain Transition]
      [Native to Managed Transition]
  </code></pre>