[c#] Runtime error: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0

I tinkered with my ASP.NET MVC4 packages via NuGet, and now System.Web.WebPages.Razor v3 won't load. Sometimes other packages won't load either.

My coworker runs the solution without any trouble, so the issue is definitely configuration on my development system (as opposed to anything that's been checked in).

I have already tried the recommendations at various SOf and other fora links, including:

As well as suggestions linked from there. I also checked the Control Panel and found no installed programs that referenced MVC. (If it matters, I'm running MS Win 7 SP 1.)

I am open to any and all suggestions.

Here's my core dump info:

Server Error in '/' Application.

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 system cannot find the file specified.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: 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 system cannot find the file specified.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of

the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.WebPages.Razor,

Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.

=== Pre-bind state information === LOG: User = CodesWithHammer LOG: DisplayName = System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified) LOG: Appbase = file:///c:/users/CodesWithHammer/documents/visual studio 2012/Projects/MPP/MPP/ LOG: Initial PrivatePath = c:\users\CodesWithHammer\documents\visual studio 2012\Projects\MPP\MPP\bin Calling assembly : Microsoft.Web.WebPages.OAuth, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

=== LOG: This bind starts in default load context. LOG: Using application configuration file: c:\users\CodesWithHammer\documents\visual studio 2012\Projects\MPP\MPP\web.config LOG: Using host configuration file: C:\Users\CodesWithHammer\Documents\IISExpress\config\aspnet.config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Users/CodesWithHammer/AppData/Local/Temp/Temporary ASP.NET Files/root/5bf3ca07/f960d9c5/System.Web.WebPages.Razor.DLL. LOG: Attempting download of new URL file:///C:/Users/CodesWithHammer/AppData/Local/Temp/Temporary ASP.NET Files/root/5bf3ca07/f960d9c5/System.Web.WebPages.Razor/System.Web.WebPages.Razor.DLL. LOG: Attempting download of new URL file:///c:/users/CodesWithHammer/documents/visual studio 2012/Projects/MPP/MPP/bin/System.Web.WebPages.Razor.DLL. LOG: Attempting download of new URL file:///c:/users/CodesWithHammer/documents/visual studio 2012/Projects/MPP/MPP/bin/System.Web.WebPages.Razor/System.Web.WebPages.Razor.DLL. LOG: Attempting download of new URL file:///C:/Users/CodesWithHammer/AppData/Local/Temp/Temporary ASP.NET Files/root/5bf3ca07/f960d9c5/System.Web.WebPages.Razor.EXE. LOG: Attempting download of new URL file:///C:/Users/CodesWithHammer/AppData/Local/Temp/Temporary ASP.NET Files/root/5bf3ca07/f960d9c5/System.Web.WebPages.Razor/System.Web.WebPages.Razor.EXE. LOG: Attempting download of new URL file:///c:/users/CodesWithHammer/documents/visual studio 2012/Projects/MPP/MPP/bin/System.Web.WebPages.Razor.EXE. LOG: Attempting download of new URL file:///c:/users/CodesWithHammer/documents/visual studio 2012/Projects/MPP/MPP/bin/System.Web.WebPages.Razor/System.Web.WebPages.Razor.EXE.

Stack Trace:

[FileNotFoundException: 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 system cannot find the file specified.] Microsoft.Web.WebPages.OAuth.PreApplicationStartCode.Start() +0

[InvalidOperationException: The pre-application start initialization method Start on type

Microsoft.Web.WebPages.OAuth.PreApplicationStartCode threw an exception with the following error message: 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 system cannot find the file specified..] System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection1 methods, Func1 setHostingEnvironmentCultures) +550 System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +132 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath) +90 System.Web.Compilation.BuildManager.ExecutePreAppStart() +135 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +516

[HttpException (0x80004005): The pre-application start initialization method Start on type

Microsoft.Web.WebPages.OAuth.PreApplicationStartCode threw an exception with the following error message: 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 system cannot find the file specified..] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9874840 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18055

(For those who read this far: I don't have enough reputation to make the tag pulling-out-my-hair. If there's an appropriate extant tag, please include that. KTHX.)

ETA: When I tried manually updating Microsoft.AspNet.Mvc to version 3, here's the error I got on Package Manager Console:

Install failed. Rolling back... Install-Package : Updating 'Microsoft.AspNet.Mvc 5.0.0' to 'Microsoft.AspNet.Mvc 3.0.20105.1' failed. Unable to find a version of 'Microsoft.AspNet.Mvc.FixedDisplayModes' that is compatible wi th 'Microsoft.AspNet.Mvc 3.0.20105.1'. At line:1 char:16 + Install-Package <<<< Microsoft.AspNet.Mvc -Version 3.0.20105.1 + CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

ETA2: I got the packages directory from my coworker. They have MS.AspNet.Mvc v5, and they're running just fine. But they ALSO have MS.AspNet.Mvc.FixedDisplayModes v5. So I'm going to add both of those in. And yes, I have backed up my entire solution. :)

ETA3: So I re-upgraded to AspNet MVC v5, and skipped the deprecated Mvc.FixedDisplayNodes. Then I got a problem with conflicting versions of AspNet.WebPages, so I used this fix: Conflicting versions of ASP.NET Web Pages detected: specified version is "1.0.0.0", but the version in bin is "2.0.0.0" in ASP.MET MVC 3

And now my project runs!

Thanks all for the help!

This question is related to c# asp.net-mvc-4 razor runtime-error

The answer is


In my case, the issue was not about binding redirects or missing/mismatched Microsoft.AspNet.Razor package/dlls, so the above solutions didn't work.

The issue, in my non-web project, was that RazorEngine+Microsoft.AspNet.Razor were installed in a different project (Project A) than the calling assembly/start-up project (Project B). Because there's no explicit reference to Razor, the System.Web.Razor did NOT get copied to /bin in a Release build.

The solution was to Install RazorEngine+Microsoft.AspNet.Razor in the application entry point (Project B, ConsoleApplication in my case), then the System.Web.Razor gets copied to /bin and everyone's happy.


I got this problem because I uninstalled VS 2012, I don't want to reinstall it back, so I downloaded the AspNetMVC4Setup.exe from Microsoft.com and fixed my problem.

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


same thing JUST happened to me with NUGET.

the following tag helped

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

Also if this is happening on the server, I had to make sure I was running the application pool on a more "privileged account" to the file system, but I don think that's your issue here


"Update-Package –reinstall Microsoft.AspNet.WebPages"

Reinstall Microsoft.AspNet.WebPages nuget packages using this command in the package manager console. 100% work!!


I got this error because such DLL (and many others) were missing in bin folder when I pubished the web application. It seemed like a bug in Visual Studio publish function. Cleaning, recompiling and publishing it again, made such DLLs to be published correctly.


In my case the issue didn't resolve by following any of the above methods. I had all the paths in my package config correct and the dll's were in place as referred, I was still getting run time error for System.Web.WebPages.Razor. I changed the localhost port number and this worked

I am not sure of why I had the issue and why changing the port number resolved it. Just posting this as I feel this might be useful for someone out there.


in the new actionmailer, "razorengine" is a dependency. The latest version of Razorengine installs the dependency to System.Web.Razor 3.0.0.

If you use an earlier version in your application (i suppose you are using actionmailer in another project and that you reference the mail functionality from another project) than you get this issue of course.

In an earlier application, i had a webapplication MVC that uses system.web.Razor version 2.0.0. Of course, i got the issue to. How to fix? => Simple!

  1. Just uninstall the entire actionmailer in your actionmailer project.
  2. Install a previous version of RazorEngin

    Install-Package RazorEngine -Version 3.3.0 (because version 3.3.0 will reference system.web.razor 2.0.0)

  3. Install actionmailer again (it will not install the latest version of RazorEngin because you allready did that yourselve)
Succes!


I had this issue when I upgraded to v3.0.0.preview4, so a downgrade to a stable version fixed this.


You can find it in Nuget Package Microsoft ASP.NET Web Pages Version 3.2.0

Microsoft ASP.NET Web Pages

If you have a reference to an earlier version than 3.0.0.0, Delete the reference, add the reference to the correct .dll in your packages folder and make sure "Copy Local" is set to "True" in the properties of the .dll.

Then in your web.config (as mentioned by @MichaelEvanchik)

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


Is there a System.Web.WebPages.Razor.dll in the bin folder of your web app? What is its version? (Explorer right click, properties) I'm guessing it's not 3.0.0.0. Just get the nuget packages for v3.0.0.0, perhaps by copying the packages folder from your colleague. Or install it manually: http://www.nuget.org/packages/Microsoft.AspNet.Mvc/3.0.20105.1

EDIT: if you copy stuff from your colleague, also copy the relevant version numbers into packages.config. This is what tells nuget which versions to put into the packages folder.


I got the same error, what worked for me is:

  1. Fix references error.
  2. Close Visual Studio.
  3. Delete Packages.
  4. Delete .vs folder.
  5. Run Project Again.
  6. Rebuild Project.

I did not want to install visual studio and development environment, so I have installed AspNetMVC4Setup.exe in Windows server 2016 machine and it solved the problem. The installer was downloaded from Microsoft website.

File properties of the installer


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net-mvc-4

Better solution without exluding fields from Binding How to remove error about glyphicons-halflings-regular.woff2 not found When should I use Async Controllers in ASP.NET MVC? How to call controller from the button click in asp.net MVC 4 How to get DropDownList SelectedValue in Controller in MVC Return HTML from ASP.NET Web API There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key country Return JsonResult from web api without its properties how to set radio button checked in edit mode in MVC razor view How to call MVC Action using Jquery AJAX and then submit form in MVC?

Examples related to razor

Uncaught SyntaxError: Invalid or unexpected token How to pass a value to razor variable from javascript variable? error CS0103: The name ' ' does not exist in the current context how to set radio button checked in edit mode in MVC razor view @Html.DropDownListFor how to set default value Razor MVC Populating Javascript array with Model Array How to add "required" attribute to mvc razor viewmodel text input editor How to correctly use Html.ActionLink with ASP.NET MVC 4 Areas Multiple radio button groups in MVC 4 Razor How to hide a div element depending on Model value? MVC

Examples related to runtime-error

ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'undefined' what does Error "Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" mean? javac: invalid target release: 1.8 C++ error : terminate called after throwing an instance of 'std::bad_alloc' Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException Error No Main class found in NetBeans Runtime error: Could not load file or assembly 'System.Web.WebPages.Razor, Version=3.0.0.0 TypeError: Cannot read property "0" from undefined Array Index Out of Bounds Exception (Java) Excel VBA Automation Error: The object invoked has disconnected from its clients