title: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.1.1
body: <p>I’m trying to upgrade a project from MVC 4/EF 5 to MVC 5/EF 6.  I updated the framework from 4.5 to 4.5.1 and then from NuGet updated the Solution MVC (4.0.30506.0 to 5.1.1) and EntityFramework (5 to 6.1.1).  This pulled in a Razor dependency (2.0.30506.0 to 3.1.1) and WebPages (2.0.30506.0 to 3.1.1).  I edited the Project and Views folder web.config to reflect the changes and removed the GUID from the csproj.</p>
  
  <p>When I run the site in debug I get an error loading the Views folder web.config on the --
     section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection -- line.</p>
  
  <blockquote>
    <p>“An error occurred creating the configuration section handler for
    system.web.webPages.razor/host: Could not load file or assembly
    'System.Web.WebPages.Razor, Version=3.1.1”</p>
  </blockquote>
  
  <p>It doesn’t have a problem on the previous line (System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup) or with the Razor reference in the root web.config.  Unfortunately the stack trace doesn’t identify the calling assembly.</p>
  
  <blockquote>
    <p>Calling assembly : (Unknown).</p>
  </blockquote>
  
  <p>All the relevant files are included below.</p>
  
  <p>Does anyone have any idea what the problem is and more importantly how to fix it.  I only updated the bare minimum NuGet Packages: MVC and Entity Framework.</p>
  
  <pre><code>        packages.config:
  
  …  
    &lt;package id="EntityFramework" version="6.1.0" targetFramework="net451" /&gt;
    &lt;package id="jQuery" version="2.0.2" targetFramework="net45" /&gt;
    &lt;package id="jQuery.UI.Combined" version="1.10.3" targetFramework="net45" /&gt;
    &lt;package id="jQuery.Validation" version="1.11.1" targetFramework="net45" /&gt;
    &lt;package id="knockoutjs" version="2.2.1" targetFramework="net45" /&gt;
    &lt;package id="Microsoft.AspNet.Mvc" version="5.1.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="5.0.0" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.Razor" version="3.1.1" targetFramework="net451" /&gt;
    &lt;package id="Microsoft.AspNet.Web.Optimization" version="1.0.0" targetFramework="net45" /&gt;
  …
    &lt;package id="Microsoft.AspNet.WebPages" version="3.1.1" targetFramework="net451" /&gt; 
  &lt;!-- oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" --&gt;
  …
  
            web.config:       root
  
  &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
  …
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.1.1" newVersion="3.1.1" /&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.1" newVersion="5.1.1" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-3.1.1" newVersion="3.1.1" /&gt;       &lt;/dependentAssembly&gt;
  
  
            web.config:       Views folder
  
     &lt;sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.1.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
   &lt;section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.1.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /&gt;
  &lt;section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.1.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /&gt;     &lt;/sectionGroup&gt;
  …
   &lt;host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
  …
      &lt;pages
          validateRequest="false"
          pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=5.1.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
          pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=5.1.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
          userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=5.1.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
        &lt;controls&gt;
          &lt;add assembly="System.Web.Mvc, Version=5.1.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" /&gt;
        &lt;/controls&gt;
      &lt;/pages&gt;
  
            ERROR PAGE:
  </code></pre>
  
  <p>Configuration Error 
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. </p>
  
  <p>Parser Error Message: An error occurred creating the configuration section handler for system.web.webPages.razor/host: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.1.1, 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)</p>
  
  <p>Source Error: </p>
  
  <pre><code>Line 4:    &lt;configSections&gt;
  Line 5:      &lt;sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.1.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
  Line 6:        &lt;section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.1.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /&gt;
  Line 7:        &lt;section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.1.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" /&gt;
  Line 8:      &lt;/sectionGroup&gt;
  </code></pre>
  
  <p>Source File:  C:\Project\views\web.config    Line:  6 </p>
  
  <p>Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.WebPages.Razor, Version=3.1.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.</p>
  
  <p>=== Pre-bind state information ===
  LOG: DisplayName = System.Web.WebPages.Razor, Version=3.1.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35
   (Partial)
  WRN: Partial binding information was supplied for an assembly:
  WRN: Assembly Name: System.Web.WebPages.Razor, Version=3.1.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35 | Domain ID: 4
  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" rel="noreferrer">http://go.microsoft.com/fwlink/?LinkId=109270</a> for more information and common solutions to this issue.
  LOG: Appbase = file:/// C:\Project /
  LOG: Initial PrivatePath = C:\Project \bin</p>
  
  <h1>Calling assembly : (Unknown).</h1>
  
  <p>LOG: This bind starts in default load context.
  LOG: Using application configuration file: C:\Project \web.config
  LOG: Using host configuration file: C:\Users\xxx\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/xxx/AppData/Local/Temp/Temporary ASP.NET Files/root/898b17f9/848c1fdf/System.Web.WebPages.Razor.DLL.
  LOG: Attempting download of new URL file:///C:/Users/xxx/AppData/Local/Temp/Temporary ASP.NET Files/root/898b17f9/848c1fdf/System.Web.WebPages.Razor/System.Web.WebPages.Razor.DLL.
  LOG: Attempting download of new URL file:/// C:\Project /bin/System.Web.WebPages.Razor.DLL.
  WRN: Comparing the assembly name resulted in the mismatch: Minor Version
  ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.</p>
  
  <p>Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18446</p>