Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with an MVC4 application trying to reference a newer version of System.Web.WebPages.Razor

I've been working on a mvc4 web application for the last few months. Everything was working great until friday when I ran an update-package in nuget to make sure that I had the most recent versions of my libraries.

Now when I try to view anything in the application it tells me that it get the error Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.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)

I've checked my web.config and my packages.config and nowhere am I referencing System.Web.WebPages.Razor, Version=3.0.0.0

I've added a dependentAssembly block to my web.config with version 2.0.0.0

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

and made sure that the web.config in my views directory also specifies v2.0.0.0

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

I've also made sure that the version referenced in my references is 2.0.0.0. I've tried removing it and readding it. I've tried making sure that the server has the most recent version of the .net framework installed.

I've tested this both on the server and locally and get the same error message.

Locally I see this in the error log LOG: Post-policy reference: System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 But i can't find any information on what is causing that.

I'm developing it in Visual Studio 2012 premium.

Anyone have any ideas?

like image 471
wmelon Avatar asked Oct 21 '13 15:10

wmelon


People also ask

Is there a cross version compatibility between Razor and MVC 5?

There is no cross version compatibility among major ASP.NET packages. For example, MVC 5 is compatible with only Razor 3, and not Razor 2. Open your project in Visual Studio. Remove any of the following ASP.NET NuGet packages that are installed. You will remove these using the Package Manager Console (PMC).

Which version of system runtime is used in MVC project?

No, no project references any version of System.Runtime directly. Some third party libraries do, for instance, Jetbrains.Annotations 11.0 depends on System.Runtime 4.1.0.0. I found that if I reference net standard lib from net framework lib project, which in turn is referenced by MVC app project, everything works fine.

How to change the GUID of a MVC 4 project?

Final Steps. 1 In Solution Explorer, right-click the project name and then select Unload Project. 2 Right-click the project and select Edit ProjectName.csproj. 3 Locate the ProjectTypeGuids element and then remove the MVC 4 project GUID, {E3E379DF-F4C6-4180-9B81-6769533ABE47}. 4 Save and close the open project file. 5

Is it possible to reference NET Standard lib from MVC project?

I found that if I reference net standard lib from net framework lib project, which in turn is referenced by MVC app project, everything works fine.


2 Answers

I've checked my web.config and my packages.config and nowhere am I referencing System.Web.WebPages.Razor, Version=3.0.0.0

That's your problem. I've ran into similar issues myself a few times. Though, it tends to happen mostly when dealing with multiple projects in one solution; I'm not sure if that applies in your case. Nevertheless, the issue boils down to the actual project reference having been "upgraded", but your web.config and packages.config not referencing that upgraded package. If you go into your project references and view properties on the Razor reference, I'd bet dollars to dimes that it says 3.0.0.0 there. You can either remove the reference and re-add it by browsing into the bin directory of the lower versioned package or upgrade it completely.

Like I said, this usually occurs in multi-project solutions when you upgrade one project but not another. The easiest way to fix it is to manage nuget packages for the entire solution. You'll then probably see multiple listings for Razor where one is checked for one or more projects but not some and vice-versa. Remove the older version of Razor (uncheck the associated projects) for the the older version and apply. Then go back to the new version of Razor and apply it to all projects it's missing from.

like image 183
Chris Pratt Avatar answered Oct 20 '22 06:10

Chris Pratt


I had a same problem, my WCF service was not working. Solution was deleting System.Web.Mvc.dll from my BIN folder.

like image 43
Boris Avatar answered Oct 20 '22 08:10

Boris