Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load file or assembly 'System.Web.WebPages'

I've had this problem before, but then all I needed to do was to clean and rebuild the project. Now that doesn't seem to work anymore. When I start my Asp.Net MVC3 project debugger, the site is opened in my browser. Instead of getting the first page presented in the browser, I get this error:

Parser Error Message: Could not load file or assembly 'System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Source Error: 
Line 31:         <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Line 32:         <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Line 33:         <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Line 34:       </assemblies>
Line 35:     </compilation>

I can't seem to figure out how to solve this. Any idea?

like image 969
Anton Gildebrand Avatar asked Jun 28 '12 14:06

Anton Gildebrand


4 Answers

The solution for me was to go to my server and install the Web Pages Version 2 on the server.

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

And download the package and run it.

It was as simple as that.

like image 53
Robert Tanenbaum Avatar answered Nov 17 '22 04:11

Robert Tanenbaum


I had this problem. Maybe it occurred when I installed .NET MVC v4 over the top of MVC v3, not sure.

Anyway I removed the System.Web.WebPages reference from my project. Then in the Add Reference dialogue .NET tab there were two System.Web.WebPages references listed, a version 1.0.0.0 and a 2.0.0.0. I made sure to add the version 1.0.0.0 one as that was the one that was missing.

enter image description here

like image 19
zuallauz Avatar answered Nov 17 '22 04:11

zuallauz


Worked for me:

  1. Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution

  2. Browse

  3. Search for "Microsoft.AspNet.WebPages"

  4. Make sure all projects in solution have the latest version.

like image 14
Doron Saar Avatar answered Nov 17 '22 05:11

Doron Saar


I scratched my head for a while over this problem when I had it. Eventually I noticed that I had the following section in the "runtime" section of my web.config.

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

As you can see, this refers to version 2 of the assembly, which doesn't match the following code that you also have in the system.web/compilation/assemblies section of web.config.

<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

The actual assembly referenced in References for the project is indeed v1.0.0.0, so I changed the first chunk of code above to the following, which fixed the problem immediately. I'm not sure how the mistake got there in the first place.

<runtime>
 . . .
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="1.0.0.0" />
      </dependentAssembly>
. . .
</runtime>
like image 6
centralscru Avatar answered Nov 17 '22 05:11

centralscru