9

The project runs fine locally, its only when published I get the following error:

Could not load file or assembly 'System.Web.Razor' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Having spent the last few hours googling the problem seems to be that a nuget package I added to the project references razor 1 and overwrote my razor 2 dll. I've tried copying the razor 2.0.0.0 dll into refernces instead of 1 but the error persists. This is where the conflict is shown in the detailed build output:

There was a conflict between "System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" and "System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35".
1>      "System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" was chosen because it was primary and "System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" was not.
1>      References which depend on "System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" [C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.Razor.dll].
1>          C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.Razor.dll
1>            Project file item includes which caused reference "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.Razor.dll".
1>              System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL
1>      References which depend on "System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" [C:\Users\Jack\SkyDrive\LessonUp.Current\packages\RazorEngine.3.0.8\lib\net40\System.Web.Razor.dll].
1>          C:\Users\Jack\SkyDrive\LessonUp.Current\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll
1>            Project file item includes which caused reference "C:\Users\Jack\SkyDrive\LessonUp.Current\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll".
1>              System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL 
1>              Recaptcha

From there it continues to list other packages depending on razor 2.

The packages I added to the project were: Recaptcha, Recaptcha.mvcModel and Postal.
Does anyone have an idea what steps I can take to resolve this?
Let me know if there is any more information I can give that might lead to a solution.

Stephan Bauer
  • 9,120
  • 5
  • 36
  • 58
jakhicks
  • 584
  • 1
  • 5
  • 8

5 Answers5

5

Make sure the 2.0 dll is referenced and copy local = true, then try adding an assembly binding redirect in the web.config:

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
</assemblyBinding?
viperguynaz
  • 12,044
  • 4
  • 30
  • 41
  • There was already an assembly binding as follows: I changed it to what you posted and the error stayed the same. I also checked the reference properties and copy local was already set to "true". Any other ideas? – jakhicks Feb 13 '13 at 23:34
  • Thanks. Setting `Copy local=true` worked for me. It seems that this should be the default for new projects, especially when adding references with nuget. – ps2goat Dec 31 '13 at 07:47
  • I changed the oldversion to be 1.0-3.0 and new version 4.0 - This fixed the problem for me after updating an old VS2012 MVC3 project in VS2013 to MVC4. – Piotr Kula Feb 11 '14 at 14:13
  • adding the redirection produces an error for me as documented here: https://razorengine.codeplex.com/workitem/1110 – ekkis Jul 05 '14 at 21:36
1

I had the same problem with Postal 0.8.0 in a MVC4 project. When you install Postal with NuGet it replaces System.Web.Razor 2.0 with System.Web.Razor 1.0. I had to delete the reference to System.Web.Razor 1.0 and then added back in System.Web.Razor 2.0. You have to additionally set Copy Local to True in the Properties for System.Web.Razor and the of course rebuild the project. Once I did that VS2012 copied the System.Web.Razor.dll to the deployed bin directory and the problem cleared.

Postal also adds these dependency's to the web.config. I removed them and it still works properly.

<dependentAssembly>
    <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
    <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
</dependentAssembly>
<dependentAssembly>
    <assemblyIdentity name="RazorEngine" publicKeyToken="9ee697374c7e744a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.0.8.0" newVersion="3.0.8.0" />
</dependentAssembly>
Erik Schierboom
  • 16,301
  • 10
  • 64
  • 81
Joe
  • 4,143
  • 8
  • 37
  • 65
0

Finally got this sorted, downloaded razor2.0 again from nuget. Seemed to sort the webconfig and fix dependency errors. Is up and running on azure not without any problem.

jakhicks
  • 584
  • 1
  • 5
  • 8
0

Check your project file and web.config to see if they've been munged by a NuGet package. A known problem child is postal 0.8.0. It pulls in as a dependency a beta version of RazorVersion (even if you've filtered to show stable only). Even if you update RazorVersion to the latest version, which is stable, your project file ends up referencing System.Web.Razor version 1, and your web.config has incorrect runtime assembly bindings.

To fix, do a diff on your project file and web.config against those of a fresh, empty MVC 4 project. Then copy over the correct Reference element for System.Web.Razor from the original project file. In web.config, delete the dependentAssembly element for System.Web.Razor.

Here's the TLDD (too lazy, didn't diff) text for your project file. Hopefully, by the time this snippet is out of date, the underlying cause(s) will be fixed.

<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <Private>True</Private>
  <HintPath>..\packages\Microsoft.AspNet.Razor.2.0.20715.0\lib\net40\System.Web.Razor.dll</HintPath>
</Reference>

(Unfortunately, you can't fix this by uninstalling and reinstalling with NuGet, because you'd have to first uninstall the offending dependent package such as postal, which will re-break things when you re-install it.)

Edward Brey
  • 40,302
  • 20
  • 199
  • 253
0

Original..

  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages.Deployment" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>

For some reason newVersion attribute was set to 2.0.0.0 version while dll was of 3.0.0.0

  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages.Deployment" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>

Than it worked

Artiom
  • 7,694
  • 3
  • 38
  • 45