title: Could not load file or assembly 'System.Web.Mvc' . How to use the correct reference?
body: <p>I have an application built on ASP.NET web forms which also supports MVC 5. I included MVC 5 API controllers in my project for which I had to upgrade Json from version 4.5 to 7.0. After making those changes when I launched the application, I get the following error:</p>
  
  <blockquote>
    <p>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)</p>
  </blockquote>
  
  <p>I checked the reference for <code>System.Web.Mvc</code>. In the property dialog run time version is <code>v4.0.30319</code> and version is <code>5.0.0.0</code>. In web.config, the assemblies are set as the following:</p>
  
  <pre><code>&lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0" /&gt;
    &lt;/dependentAssembly&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="AntiXssLibrary" publicKeyToken="d127efab8a9c114f" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" /&gt;
    &lt;/dependentAssembly&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.WebPages" 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="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" /&gt;
    &lt;/dependentAssembly&gt;
    &lt;!--&lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" /&gt;
    &lt;/dependentAssembly&gt;--&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /&gt;
    &lt;/dependentAssembly&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /&gt;
    &lt;/dependentAssembly&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
      &lt;bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /&gt;
    &lt;/dependentAssembly&gt;
  &lt;/assemblyBinding&gt;
  </code></pre>
  
  <p>The full error log is shown below:</p>
  
  <blockquote>
    <p>=== 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
    <a href="http://go.microsoft.com/fwlink/?LinkId=109270">http://go.microsoft.com/fwlink/?LinkId=109270</a> for more information and
    common solutions to this issue. LOG: Appbase =
    file:///C:/Users/Ahmed/Documents/Visual Studio
    2013/Projects/MediaSoft/Project/c#/YuClone/YuClone/ LOG: Initial
    PrivatePath = C:\Users\Ahmed\Documents\Visual Studio
    2013\Projects\MediaSoft\Project\c#\YuClone\YuClone\bin Calling
    assembly : (Unknown).
    === LOG: This bind starts in default load context. LOG: Using application configuration file: C:\Users\Ahmed\Documents\Visual Studio
    2013\Projects\MediaSoft\Project\c#\YuClone\YuClone\web.config LOG:
    Using host configuration file:
    C:\Users\Ahmed\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:/Users/Ahmed/AppData/Local/Temp/Temporary ASP.NET
    Files/root/22a49c5f/2f5ffeb9/System.Web.Mvc.DLL. LOG: Attempting
    download of new URL
    file:///C:/Users/Ahmed/AppData/Local/Temp/Temporary ASP.NET
    Files/root/22a49c5f/2f5ffeb9/System.Web.Mvc/System.Web.Mvc.DLL. LOG:
    Attempting download of new URL file:///C:/Users/Ahmed/Documents/Visual
    Studio
    2013/Projects/MediaSoft/Project/c#/YuClone/YuClone/bin/System.Web.Mvc.DLL.
    LOG: Using application configuration file:
    C:\Users\Ahmed\Documents\Visual Studio
    2013\Projects\MediaSoft\Project\c#\YuClone\YuClone\web.config LOG:
    Using host configuration file:
    C:\Users\Ahmed\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: 5.0.0.0
    redirected to 5.2.3.0. LOG: Post-policy reference: System.Web.Mvc,
    Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG:
    Attempting download of new URL
    file:///C:/Users/Ahmed/AppData/Local/Temp/Temporary ASP.NET
    Files/root/22a49c5f/2f5ffeb9/System.Web.Mvc.DLL. LOG: Attempting
    download of new URL
    file:///C:/Users/Ahmed/AppData/Local/Temp/Temporary ASP.NET
    Files/root/22a49c5f/2f5ffeb9/System.Web.Mvc/System.Web.Mvc.DLL. LOG:
    Attempting download of new URL file:///C:/Users/Ahmed/Documents/Visual
    Studio
    2013/Projects/MediaSoft/Project/c#/YuClone/YuClone/bin/System.Web.Mvc.DLL.
    WRN: Comparing the assembly name resulted in the mismatch: Minor
    Version ERR: Failed to complete setup of assembly (hr = 0x80131040).
    Probing terminated.</p>
  </blockquote>
  
  <p>Following is the <strong>Stack Trace</strong></p>
  
  <blockquote>
    <p>[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)]</p>
    
    <p>[FileLoadException: Could not load file or assembly 'System.Web.Mvc,
    Version=5.2.3.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<br>
    System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String
    codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint,
    StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean
    throwOnFileNotFound, Boolean forIntrospection, Boolean
    suppressSecurityChecks) +36<br>
    System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName
    assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly,
    StackCrawlMark&amp; stackMark, IntPtr pPrivHostBinder, Boolean
    throwOnFileNotFound, Boolean forIntrospection, Boolean
    suppressSecurityChecks) +152<br>
    System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,
    Evidence assemblySecurity, StackCrawlMark&amp; stackMark, IntPtr
    pPrivHostBinder, Boolean forIntrospection) +77<br>
    System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString,
    Evidence assemblySecurity, StackCrawlMark&amp; stackMark, Boolean
    forIntrospection) +21    System.Reflection.Assembly.Load(String
    assemblyString) +28<br>
    System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String
    assemblyName, Boolean starDirective) +38</p>
    
    <p>[ConfigurationErrorsException: Could not load file or assembly
    'System.Web.Mvc, Version=5.2.3.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)]<br>
    System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String
    assemblyName, Boolean starDirective) +738<br>
    System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
    +217    System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo
    ai) +130<br>
    System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection
    compConfig) +170<br>
    System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()
    +92    System.Web.Compilation.BuildManager.CallPreStartInitMethods(String
    preStartInitListPath, Boolean&amp; isRefAssemblyLoaded) +290<br>
    System.Web.Compilation.BuildManager.ExecutePreAppStart() +157<br>
    System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager
    appManager, IApplicationHost appHost, IConfigMapPathFactory
    configMapPathFactory, HostingEnvironmentParameters hostingParameters,
    PolicyLevel policyLevel, Exception appDomainCreationException) +531</p>
    
    <p>[HttpException (0x80004005): Could not load file or assembly
    'System.Web.Mvc, Version=5.2.3.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)]<br>
    System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9924184 
    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)
    +101    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest
    wr, HttpContext context) +261</p>
  </blockquote>
  
  <p>How do I upgrade the version of System.Web.Mvc to point to the correct assembly?</p>