VS 2015 : Could not load file or assembly 'System.Web.WebPages.Razor, Version=2.0.0.0
Asked Answered
E

4

10

I am running a solution which contains different projects. However, i am trying to run a project (class library) which contains wcf services using Visual Studio 2015 and framework 4.6 (on windows 8 OS, IIS Express). However it keeps showing this error in the browser:

Error:

enter imag*e description here

I noticed that the calling assembly of Razor 2.0 is "System.Web.Mvc" Version 4.0.0.1:

Calling assembly : System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

However, System.Web.MVC dll is not referenced in this project, the references in the project are in the image below:

enter image description here

Although, it is not referenced it always appears in the bin folder, even when i clear it. And may be that's why it is trying to call "System.Web.WebPages.Razor" version 2.0.

Clarifying any clues of the problem:

  1. I have no related assembly in the Web.Config that calls System.web.mvc

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
     
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  1. also not included in package config:

<packages>
  <package id="EntityFramework" version="6.1.3" targetFramework="net46" />
  <package id="Microsoft.AspNet.Providers" version="2.0.0" targetFramework="net451" />
  <package id="Microsoft.AspNet.Providers.Core" version="2.0.0" targetFramework="net451" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" />
  <package id="PostSharp" version="4.3.5-alpha" targetFramework="net46" />
  <package id="System.Web.Providers" version="1.2" targetFramework="net451" />
</packages>
  1. not included as a reference

I am wondering about whats going on? may another project affects it! Also i have tried to use nugget to update the packages (uninstalled and reinstalled), but still in the same situation.

A possible reason of the problem:

I also noticed there is a "Gobal.asax" file in this project which uses "MvcApplication" class that implements "System.Web.HttpApplication" which may be a good reason of the problem.

Any help is appreciated.

Eritrea answered 30/3, 2016 at 21:33 Comment(0)
E
16

Solution: install Microsoft.AspNet.Webpages first release of version 2.0 via nuget manager.

Eritrea answered 1/4, 2016 at 0:16 Comment(5)
This helped me.Equivocation
This helped me, too.Courtneycourtrai
Thank you this fixed my problemArjuna
I also deleted my bin folderOstraw
And delete obj folder too. Sometimes copy-paste of project is not a good idea.Microclimatology
D
1

I would start by looking at assembly binding failures - this will show you which assembly is requesting that failing binding.

There is a handy little tool you can use to view your binding failures. This should help you track it down.

https://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.71).aspx

Good luck!

Dextrosinistral answered 30/3, 2016 at 22:17 Comment(1)
PS location here: C:\Program Files (x86)\Microsoft SDKs\Windows{version}\bin{.NET Version Tools}Dextrosinistral
S
0

in my case, the error was after deploying, and the issue was a reference in a web.config within a sub folder of that server.

i troubleshot this by remoting into that machine and browsing the site locally (or you can enable remote errors in web.config)

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

So be sure to search all your files for 2.0.0.0 or System.Web.WebPages.Razor to make sure there is no reference somewhere!

Soembawa answered 28/6, 2017 at 16:53 Comment(0)
F
0

I was getting this error, but the project from which the error is throwing has the Microsoft.AspNet.Webpages installed properly. Then I realised that the WCF services which are kept in a separate project lost it's MVC installation.

So installing Microsoft.AspNet.Mvc in my other project fixed this error for me.

Feltie answered 19/1, 2020 at 17:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.