title: App is building but failing to load - System.Web.Mvc missing file or assembly?
body: <p>I did a "Get Latest" recently on an MVC Project in TFS, and now when I try to run it, the result every time is the yellow screen of failure, stating:</p>
  
  <pre><code>Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
  
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
  Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
  
  Source Error: 
  
  
  Line 17:             RouteConfig.RegisterRoutes(RouteTable.Routes);
  Line 18:             BundleConfig.RegisterBundles(BundleTable.Bundles);
  Line 19:         }
  Line 20:     }
  Line 21: }
  
  Source Line: 19
  </code></pre>
  
  <p>The file in question is pasted below:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using System.Web.Optimization;
  using System.Web.Routing;
  
  namespace PROJECTdev
  {
      public class MvcApplication : System.Web.HttpApplication
      {
          protected void Application_Start()
          {
              AreaRegistration.RegisterAllAreas();
              FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
              RouteConfig.RegisterRoutes(RouteTable.Routes);
              BundleConfig.RegisterBundles(BundleTable.Bundles);
          }
      }
  }
  </code></pre>
  
  <p>Anyone have any ideas on why this is occurring, and how to fix it?</p>
  
  <p>I have so far attempted a Clean/Build of the solution, and even went so far in TFS as to remove my current mapping and do an entirely new Map/Download of the project -- this lead to further issues, but after all the trouble of resolving them with fixing broken references and more, I'm right back at square one...</p>
  
  <p>Any help appreciated.</p>
  
  <p>I've pasted the Assembly Load Trace below if it helps:</p>
  
  <pre><code>Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.
  
  === Pre-bind state information ===
  LOG: DisplayName = System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
   (Fully-specified)
  LOG: Appbase = file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/
  LOG: Initial PrivatePath = C:\John-Projects\PROJECT\PROJECTdev\PROJECTdev\bin
  Calling assembly : PROJECTdev, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
  ===
  LOG: This bind starts in default load context.
  LOG: Using application configuration file: C:\John-Projects\PROJECT\PROJECTdev\PROJECTdev\web.config
  LOG: Using host configuration file: C:\Users\jsmith\Documents\IISExpress\config\aspnet.config
  LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
  LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 5.1.0.0.
  LOG: Post-policy reference: System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
  LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc.DLL.
  LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc/System.Web.Mvc.DLL.
  LOG: Attempting download of new URL file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/bin/System.Web.Mvc.DLL.
  LOG: Attempting download of new URL file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/bin/System.Web.Mvc/System.Web.Mvc.DLL.
  LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc.EXE.
  LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc/System.Web.Mvc.EXE.
  LOG: Attempting download of new URL file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/bin/System.Web.Mvc.EXE.
  LOG: Attempting download of new URL file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/bin/System.Web.Mvc/System.Web.Mvc.EXE.
  </code></pre>
  
  <p>Stack Trace: </p>
  
  <pre><code>[FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
  
  [FileNotFoundException: Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
     PROJECTdev.MvcApplication.Application_Start() in c:\john-Projects\PROJECT\PROJECTdev\PROJECTdev\Global.asax.cs:19
  
  [HttpException (0x80004005): Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
     System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9936485
     System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
     System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
     System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
     System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
  
  [HttpException (0x80004005): Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.]
     System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9950728
     System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
     System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
  </code></pre>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>While I am not getting any Errors for the Build, I am getting the following warning (regarding the first one, not sure how to set "log verbosity" to "detailed"):</p>
  
  <p><img src="https://i.stack.imgur.com/HcKpz.jpg" alt="enter image description here"></p>
  
  <p><strong>EDIT2</strong>:</p>
  
  <p>So, I do not know what changed, but this morning my properties for <code>System.Web.Mvc</code> were selectable, and I was able to turn <code>Copy Local</code> Property to <code>True</code>. Now when I run the application, I get the following:</p>
  
  <pre><code>Server Error in '/' Application.
  
  Could not load file or assembly 'System.Web.Mvc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
  
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
  
  Exception Details: System.IO.FileLoadException: Could not load file or assembly 'System.Web.Mvc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
  
  Source Error: 
  
  An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
  
  Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Mvc' could not be loaded.
  
  
  === Pre-bind state information ===
  LOG: DisplayName = System.Web.Mvc
   (Partial)
  WRN: Partial binding information was supplied for an assembly:
  WRN: Assembly Name: System.Web.Mvc | Domain ID: 2
  WRN: A partial bind occurs when only part of the assembly display name is provided.
  WRN: This might result in the binder loading an incorrect assembly.
  WRN: It is recommended to provide a fully specified textual identity for the assembly,
  WRN: that consists of the simple name, version, culture, and public key token.
  WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
  LOG: Appbase = file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/
  LOG: Initial PrivatePath = C:\John-Projects\PROJECT\PROJECTdev\PROJECTdev\bin
  Calling assembly : (Unknown).
  ===
  LOG: This bind starts in default load context.
  LOG: Using application configuration file: C:\John-Projects\PROJECT\PROJECTdev\PROJECTdev\web.config
  LOG: Using host configuration file: C:\Users\jSmith\Documents\IISExpress\config\aspnet.config
  LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
  LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
  LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc.DLL.
  LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc/System.Web.Mvc.DLL.
  LOG: Attempting download of new URL file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/bin/System.Web.Mvc.DLL.
  LOG: Using application configuration file: C:\John-Projects\PROJECT\PROJECTdev\PROJECTdev\web.config
  LOG: Using host configuration file: C:\Users\jSmith\Documents\IISExpress\config\aspnet.config
  LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
  LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 5.1.0.0.
  LOG: Post-policy reference: System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
  LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc.DLL.
  LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/8b582d3d/20022f9a/System.Web.Mvc/System.Web.Mvc.DLL.
  LOG: Attempting download of new URL file:///C:/John-Projects/PROJECT/PROJECTdev/PROJECTdev/bin/System.Web.Mvc.DLL.
  WRN: Comparing the assembly name resulted in the mismatch: Major Version
  ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
  
  Stack Trace: 
  
  
  [FileLoadException: Could not load file or assembly 'System.Web.Mvc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
  
  [FileLoadException: Could not load file or assembly 'System.Web.Mvc, Version=5.1.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)]
     System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
     System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
     System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
     System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +77
     System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark&amp; stackMark, Boolean forIntrospection) +16
     System.Reflection.Assembly.Load(String assemblyString) +28
     System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +38
  
  [ConfigurationErrorsException: Could not load file or assembly 'System.Web.Mvc, Version=5.1.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)]
     System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +752
     System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +218
     System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +130
     System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +170
     System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +91
     System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean&amp; isRefAssemblyLoaded) +285
     System.Web.Compilation.BuildManager.ExecutePreAppStart() +153
     System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +521
  
  [HttpException (0x80004005): Could not load file or assembly 'System.Web.Mvc, Version=5.1.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)]
     System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9950728
     System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
     System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
  </code></pre>
  
  <p>Anyone have thoughts on where to go from here?</p>
  
  <p>Referencing <strong><em><a href="https://stackoverflow.com/questions/4255118/could-not-load-file-or-assembly-system-web-mvc-or-one-of-its-dependencies">this</a></em></strong> post, I dug into my <code>bin</code> folder and found that the <code>System.Web.Mvc.dll</code> file is version <code>4.0.20710.0</code> and is defined I believe appropriately in my <code>Web.config</code> file:</p>
  
  <pre><code>&lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
  </code></pre>
  
  <p><strong>EDIT3</strong>:</p>
  
  <p>Taking a look at <strong><em><a href="http://haacked.com/archive/2011/05/25/bin-deploying-asp-net-mvc-3.aspx/" rel="nofollow noreferrer">this</a></em></strong> article, I made sure all of the listed references are indeed in my application:</p>
  
  <p><img src="https://i.stack.imgur.com/15jwx.jpg" alt="References"></p>
  
  <p>When I didn't see <code>Microsoft.Web.Infrastructure</code> in my list, I thought I'd found the issue, but it appears not to be so:</p>
  
  <pre><code>PM&gt; Install-Package Microsoft.Web.Infrastructure
  'Microsoft.Web.Infrastructure 1.0.0.0' already installed.
  PROJECTdev already has a reference to 'Microsoft.Web.Infrastructure 1.0.0.0'.
  </code></pre>
  
  <p><strong>EDIT4</strong> -- (Honorable Chow's Suggestion):</p>
  
  <ul>
  <li><strong>1.) In Visual Studio go to Tools => Extensions and Updates. If there is an update to NuGet update it then close and reopen the project. It may be that the packages have changed and if you don't have the latest version the packages won't get automatically updated like they should.</strong></li>
  </ul>
  
  <p>There was an update to VS2013 (Update 4), but still the same issue.</p>
  
  <ul>
  <li><strong>2.) Delete your bin/obj directories. Cleaning the solution doesn't always completely clean and you may have an old assembly in one of these directories.</strong></li>
  </ul>
  
  <p>I cleared out these folders as instructed, and now my project is failing to build with 43 errors. Most of them involve being unable to find <code>The type or namespace name</code>: <code>DbSet</code>, <code>Entity</code>, and one each for <code>DbMigration</code>/<code>DbMigrationsConfiguration</code>. The Big error that seems to be causing all of the others is as follows:</p>
  
  <pre><code>The type 'System.Data.Entity.DbContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
  </code></pre>
  
  <p>I then tried to add the specified Package and Version via Nuget command <code>Install-Package EntityFramework -Version 6.0.0</code> which resulted in:</p>
  
  <pre><code>PM&gt; Install-Package EntityFramework -Version 6.0.0
  Updating 'EntityFramework' from version '6.1.0' to '6.0.0' in project 'PROJECTdev'.
  Install-Package : Updating 'EntityFramework 6.1.0' to 'EntityFramework 6.0.0' failed. Unable to find a version of 'Microsoft.AspNet.Identi
  ty.EntityFramework' that is compatible with 'EntityFramework 6.0.0'.
  At line:1 char:16
  + Install-Package &lt;&lt;&lt;&lt;  EntityFramework -Version 6.0.0
      + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
      + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
  </code></pre>
  
  <p>Thoughts on this?</p>
  
  <ul>
  <li><strong>3.) In the Web.Config look at the binding redirects in the runtime=>assemblyBinding section. The new version value should be the newer version.</strong></li>
  </ul>
  
  <p>I've copied my <code>&lt;runtime&gt;&lt;assemlbyBinding&gt;</code> section of <code>Web.config</code> below. I do not see anything amiss:</p>
  
  <pre><code>   &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
  </code></pre>
  
  <ul>
  <li><strong>4.) Look at each of the assemblies in each of the projects and find the one that is using the wrong version. Remove the reference and re-add it.</strong></li>
  </ul>
  
  <p>I only have the one project in this particular solution. I'm unsure which assembly is the wrong version?</p>