Failed to load file or assembly "System.Web.WebPages.Razor, Version = 2.0.0.0

I just updated the packages in the MVC 3 project (ASP.net 4), and now I get the following error message while accessing the page in this project:

Server error in "/ MyApplication" application.

Failed to load file or assembly 'System.Web.WebPages.Razor, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35' or one of its dependencies. The installed assembly manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) Description: An unhandled exception occurred during the execution of the current web request. Look at the stack trace for more information about the error and its occurrence in the code.

Exception Details: System.IO.FileLoadException: Failed to load file or assembly "System.Web.WebPages.Razor, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 'or one of its dependencies. The installed assembly manifest definition is not corresponds to the Help assembly. (Exception from HRESULT: 0x80131040)

Source Error:

An unhandled exception was thrown during the execution of the current web request. Information about the origin and location of the exception can be identified using the exception stack trace below.

Assembly download trace: the following information may be useful to determine why the assembly 'System.Web.WebPages.Razor, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35' could not be loaded.

=== Pre-binding status information === LOG: User = IIS APPPOOL \ ASP.NET v4.0 LOG: DisplayName = System.Web.WebPages.Razor, Version = 2.0.0.0, Culture = Neutral, PublicKeyToken = 31bf3856ad364e35 ( Fully indicated) LOG: Appbase = file: /// C: /.../LOG: Initial PrivatePath = C: ... \ bin Build call: Microsoft.Web.Helpers, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35. === LOG: This binding starts with the default load context. LOG: Using the application configuration file: C: ... \ web.config LOG: using the host Configuration file: C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ aspnet.config LOG: Using the machine configuration file from C: \ Windows \ Microsoft.NET \ Framework64 \ v4.0.30319 \ Config \ machine.config. LOG: Post-policy link: System.Web.WebPages.Razor, Version = 2.0.0.0, Culture = Neutral, PublicKeyToken = 31bf3856ad364e35 LOG: Attempting to load a new URL File: /// C: /Windows/Microsoft.NET/Framework64/ v4.0.30319 / Temporary ASP.NET/.../cb62a7b2/327a0353/System.Web.WebPages.Razor.DLL files. LOG: attempt to load a new URL File: /// C: /Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files /.../cb62a7b2/327a0353/System.Web.WebPages.Razor/ System.Web.WebPages.Razor.DLL. LOG: attempt to load a new URL File: /// C: /LeGroupeHtmSVN/.../UpDir.Web/bin/System.Web.WebPages.Razor.DLL. WRN: comparing the assembly name led to a mismatch: major Version ERR: failed to complete the assembly setup (hr = 0x80131040). Study terminated.

Stack trace:

[FileLoadException: Unable to load file or assembly 'System.Web.WebPages.Razor, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35' or one of its dependencies. The installed assembly manifest definition does not match the Help assembly. (Exception from HRESULT: 0x80131040)]
Microsoft.Web.Helpers.PreApplicationStartCode.Start () +0

[InvalidOperationException: initializing start before application Method Start as Microsoft.Web.Helpers.PreApplicationStartCode threw an exception with the following error message: Failed to load file or assembly "System.Web.WebPages.Razor, Version = 2.0.0.0, Culture = neutral , PublicKeyToken = 31bf3856ad364e35 'or one of its dependencies. The installed assembly manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).]
System.Web.Compilation.BuildManager.InvokePreStartInitMethods (ICollection`1 methods) +11711966
System.Web.Compilation.BuildManager.CallPreStartInitMethods () +465
System.Web.Hosting.HostingEnvironment.Initialize (ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1167

[HttpException (0x80004005): Initialization of the launch before the application The Start method as Microsoft.Web.Helpers.PreApplicationStartCode threw an exception with the following error message: Failed to load file or assembly "System.Web.WebPages.Razor, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35 'or one of its dependencies. The established definition of the assembly manifest does not match the assembly reference. (Exception from HRESULT: 0x80131040).]
System.Web.HttpRuntime.FirstRequestInit (HttpContext context) +11700896 System.Web.HttpRuntime.EnsureFirstRequestInit (HttpContext context) +141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate (IIS71269 context +)

----------------------------------------------- --- ------------------------------ Version Information: Microsoft.NET Framework Version: 4.0.30319; ASP.NET Version: 4.0.30319.272

In my web.config file and in my application, I refer to System.Web.WebPages.Razor v1.0.0.0:

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

I donโ€™t even know if I can use System.Web.WebPages.Razor v2.0.0.0 with .Net 4.

Now, how do I know what is referencing System.Web.WebPages.Razor v2.0.0.0?

+54
dependencies asp.net-mvc-3 razor
Jun 12 2018-12-12T00:
source share
14 answers

How to find out what System.Web.WebPages.Razor v2.0.0.0 refers to?

Just read your stacktrace exception:

 Calling assembly : Microsoft.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 

So, you are using Microsoft.Web.Helpers , which in turn depends on System.Web.WebPages.Razor, Version=2.0.0.0 .

+27
Jun 12 '12 at 16:12
source share

So simple. In the Nuget package manager console:

Update package Microsoft.AspNet.Mvc -Reinstall

+54
Jun 10 '15 at 11:06
source share

This problem started when I did "Delete Unused Links". The website still worked on my local machine, but after publishing it didnโ€™t work on the server.

Remove unused references

I fixed this problem by doing the following:

  • Open the Package Manager Console in Visual Studio
  • Uninstall package Microsoft.AspNet.Mvc
  • Microsoft.AspNet.Mvc Installation Package
+50
Dec 18 '12 at 1:20
source share

After much pain, searching on Google and my hair, I ended up uninstalling MVC 4 with nuget, removing all the MVC, razor, and infrastructure links from the web configuration, deleting the DLL from the bin folder, and then using nuget to reinstall everything. It took less time to figure out why the dll is not matching.

+8
Oct 15 '13 at 21:09
source share

In ASP.NET MVC 4, the namespace is not System.Web.WebPages.Razor, but System.Web.Razor

This worked for me by modifying your web.config.

+7
Mar 16 '13 at 16:31
source share

I was getting the same error after adding an unnecessary link to System.Web.Mvc . I deleted all the links I could find, but nothing worked. I finally deleted the bin project bin and the error went away after recovery.

+2
Mar 23 '17 at 18:21
source share

I uninstalled ASP.NET MVC 4 using the Windows Control Panel and then reinstalled it by running AspNetMVC4Setup.exe (which I got from https://www.microsoft.com/en-us/download/details.aspx?id=30683 ), and this fixed the problem for me.

In other words, I did not need to use Nuget or Visual Studio.

+1
Mar 07 '17 at 22:30
source share

I also got this error and tried everything I could find on the Internet, and it did not disappear. In the end, I just downgraded MVC from 5.2.3 to 4.0.40804. I do not like this solution, because in the end I will need to use MVC 5, but it works now. Hope this helps others.

+1
May 26 '17 at 15:52
source share

Short:
You have this problem with a clean web API project (and therefore don't need a razor), try adding it anyway, rebuild it, and then delete it.

Long story:
I had this problem with a brand new clean web API project, except that stacktrace specified "System.Web.Mvc" as the Calling assembly (see Darin's answer). No reference to MVC, Razor, or anything like that in my project, though ...
I decided to add MVC packages (AspNet.Mvc, AspNet.WebPages and AspNet.Razor) to check if the following problem occurred.
The WebApi application was launched perfectly. Then I deleted the same packages, and everything was fine.

Hope this helps someone.

+1
Aug 11 '17 at 14:35
source share

In some cases, just install webpage 2 to solve this problem (resolved in my case - deploy to a local webpage using web api)

https://www.microsoft.com/en-us/download/details.aspx?id=34600

0
Jul 24 '17 at 2:13 on
source share

If the previous working project fails suddenly with the indicated error, you can try the following solution.

  • Delete the bin folder of the corresponding web project / service.
  • Build

It worked for me.

0
Oct 25 '17 at 12:41 on
source share

For such assembly binding errors, the following steps may help:

  1. Right-click your solution and select Manage Nuget Packages to Solution ...
  2. go to the "Consolidation" tab (last tab) and check if there are any differences between the packages installed in different projects inside your solution. especially pay attention to the projects you refer to, which may have lower versions, because they are usually less noticeable)
  3. specifically bundle the packages associated with your build error, and note that many packages depend on some other packages, such as * .code & * .api & ...
  4. After resolving all prospective consolidations, rebuild and restart the application and see if assembly bindings are allowed.
0
Mar 16 '19 at 8:28
source share

At first I tried to answer Muhammad Emad - without joy. Then i tried

 git clean -x -d -f 

which led me to a new "Roslyn" error, which I was able to fix by manually editing my .csproj .

Interestingly, after I read a little further down the Roslinโ€™s question page, I found another suggestion with even more votes ( Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r ). Thinking it was better to implement this than manually editing .csproj, I discarded my .csproj changes, but found that my solution still works.

So, after all this, I wonder if the answer of Muhammad (on this page) would have achieved the goal, if I had just done the purge first.

0
May 2, '19 at 3:32
source share

I was getting the same error when upgrading MVC4 to MVC5 version. First I updated the calling assembly, which depended on

 > System.Web.WebPages.Razor, Version=2.0.0.0 

after that I updated the web.config files in the Views folder, updated the following packages from

 <configSections> <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> </configSections> 

at

 <configSections> <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=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> 

as well as being updated

 <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 

at

 <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 

these steps work for me

0
May 25 '19 at 8:07
source share



All Articles