Problem
We have an ASP.Net 5.2.3 project that we are attempting to upgrade to .NET 4.6.
When running it, we get the error message
Could not load file or assembly 'System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Note that we installed Microsoft.AspNet.Razor version 3.2.3 from NuGet, though the error message refers to version 3.0.0.0.
Hack
Now if I manually copy
packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll
to
TheWebProject\bin
the project runs just fine.
GAC
Note that there are two entries in
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Web.Razor
v4.0_1.0.0.0__31bf3856ad364e35
v4.0_2.0.0.0__31bf3856ad364e35
I'm aware that DLLs that are present in the GAC ignore CopyLocal=True. However, I don't understand why the project is both unable to resolve the reference from the GAC, and unwilling to copy the version referenced using NuGet to the bin folder.
web.config
We have the following binding redirects in web.config that were presumably placed there by the NuGet installer
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
We also tried setting newVersion="3.2.3.0" to match the version as it appears in the NuGet package manager. When we change both of those to
<bindingRedirect oldVersion="0.0.0.0-3.2.3.0" newVersion="3.2.3.0" />
we get a slightly different error
Could not load file or assembly 'System.Web.WebPages.Razor' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Question
How should the project references be setup to resolve this issue?