2

My local version of my code runs just fine. But when I do a web deploy I am getting the following exception:

Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.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)

The relevant stack trace line is

[FileLoadException: Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.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)] Microsoft.Web.WebPages.OAuth.PreApplicationStartCode.Start() +0

This seems to be related to the fact that the Nuget Package for Razor is version 3.0 but the DotNetOpenAuth package uses version 2.0

Also the issue only happens when I deploy to my Azure website. (I am currently using the free website and not the webrole/workrole stuff). I use a webdeploy and it was working ok in previous versions but I believe this has something to do with nuget packages.

Update: I am unable to solve this. I have tried to deploy via FTP that deleted the whole folder prior to deployment but this did not work either. Nuget has been a nightmare.

DanScan
  • 831
  • 2
  • 10
  • 23
  • Check this out http://stackoverflow.com/questions/19741860/cannot-utilize-simplemembership-features-when-hosting-on-azure – WannaCSharp Nov 03 '13 at 03:09
  • I saw that post and I added everything to be local copy true. But this issue I see here is that one package (Open Auth) is referencing version 2 of the razor dll while I have version 3 of the razor dll from the mvc project. – DanScan Nov 03 '13 at 04:40
  • @DanScan - unsure if you are still having this problem but a late comment made me revisit my post and I added some additional information. – Tommy Jan 10 '14 at 14:01
  • I had a similar issue & it was due to older DLLs in the bin directory that had not been removed during an upgrade deployment. Once I cleaned out the bin directory and added only what was needed, the site ran fine (which is essentially the same as the answer below about deploying to Azure). – Appetere Jan 13 '14 at 12:25

3 Answers3

3

Place this in your web.config file. It will cause the framework to redirect dependencies to the appropriate version.

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <configuration>

Edit from the future

As I revisit this post because of a XML error pointed out in the above syntax, there are a few other places that most likely need updated as well. First, in the primary web.config, this line should be changed in the <appSettings> section to the following

<appSettings>
    <add key="webpages:Version" value="3.0.0.0" />

Also, there is a web.config in the views folder that should be updated to the following

 <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

Basically, you want to identify all of the places that mention razor 2.0.0.0 and change those to 3.0.0.0 in addition to the assembly redirect. I believe I have all of those locations identified above.

If you update the entire MVC framework, there is additional work that would need to be performed as well, but that is not the basis for the question.

Tommy
  • 39,592
  • 10
  • 90
  • 121
  • 1
    I tried that. It broke the local version also. I also tried various locations for this value with no luck. I firmly believe that this has something to do with OAuth looking for version 2 but the MVC package uses version 3 of the Razor package. – DanScan Nov 04 '13 at 01:09
  • According to MSDN should be a child of so I don't think it should be inside the element. See http://msdn.microsoft.com/en-us/library/twy1dw1e%28v=vs.110%29.aspx. But I have the same problem and this didn't fix it either :-( – Appetere Jan 10 '14 at 13:47
  • @Steve - when reviewing this post based on your comment, I added some additional information that may help solve the error. Preview and see if the additional information helps you! – Tommy Jan 10 '14 at 14:00
  • I am coming across this same issue now, using MVC5 and Web.API 2.2. In this latest version, both config files in both projects already have that code, yet I have the same issue as the OP. – Mason240 Nov 07 '14 at 21:27
2

I had the same problem. I was deploying to an Azure website where I had previously deployed an MVC4 app. I fixed it by "removing additional files at destination".

Right click on project->publish->Settings->expand File Publish Options-> check Remove additional files at destination.

bigE7
  • 21
  • 1
  • 3
  • The solution (although not really an answer) to this was to remove the latest version of the nuget MVC. Then from the command line load the appropriate version. OAuth packages required a different version of the razor then was being loaded by the MVC package. – DanScan Dec 06 '13 at 19:38
0

I use Git deployment and was having the same issue. I didn't see an option where I could remove additional files at destination.

I used FTP to connect to the Azure Host and then deleted everything in the /site/wwwroot directory. Then I used the Management Portal, Deployments tab, and finally the Sync command (i.e. redeploy) and that fixed the issue.

Rick Glos
  • 2,466
  • 2
  • 29
  • 30