C# 无法加载文件或程序集“System.Web.WebPages”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11246861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 17:06:52  来源:igfitidea点击:

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

c#asp.net-mvc-3

提问by Anton Gildebrand

I've had this problem before, but then all i needed to do was to clean and rebuild the project. Now that doesnt 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

我以前遇到过这个问题,但是我需要做的就是清理和重建项目。现在这似乎不再起作用了。当我启动我的 Asp.Net MVC3 项目调试器时,该站点在我的浏览器中打开。我没有在浏览器中显示第一页,而是收到此错误

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?

我似乎无法弄清楚如何解决这个问题。任何的想法?

采纳答案by zuallauz

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

我有这个问题。也许它发生在我在 MVC v3 之上安装 .NET MVC v4 时,不确定。

Anyway I removed the System.Web.WebPagesreference 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.

无论如何,我System.Web.WebPages从我的项目中删除了参考。然后在“添加引用”对话框 .NET 选项卡中列出了两个 System.Web.WebPages 引用,一个版本 1.0.0.0 和一个 2.0.0.0。我确保添加了 1.0.0.0 版本,因为那是缺少的版本。

enter image description here

在此处输入图片说明

回答by centralscru

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.

当我遇到这个问题时,我为这个问题挠了一阵子。最终我注意到我的 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.

如您所见,这是指程序集的第 2 版,它与您在 web.config 的 system.web/compilation/assemblies 部分中的以下代码不匹配。

<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.

项目引用中引用的实际程序集确实是 v1.0.0.0,因此我将上面的第一块代码更改为以下代码,立即解决了问题。我不确定错误最初是如何发生的。

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

回答by Robert Tanenbaum

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

我的解决方案是转到我的服务器并在服务器上安装网页版本 2。

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

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

And download the package and run it.

并下载包并运行它。

It was as simple as that.

就这么简单。

回答by Ravenix

I had this issue, all I had to do was change the property of the external reference: Specific Version from Trueto False

我遇到了这个问题,我所要做的就是更改外部引用的属性:Specific Version from Trueto False

After that the project build again.

之后,项目再次构建。

回答by Doron Saar

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.

  1. 工具 -> NuGet 包管理器 -> 管理解决方案的 NuGet 包

  2. 浏览

  3. 搜索“Microsoft.AspNet.WebPages”

  4. 确保解决方案中的所有项目都具有最新版本。

回答by reza.cse08

I have fetch same problem for MVC5.

我为 MVC5 获取了同样的问题。

At First Check your System.Web.WebPagesassembly from Reference of your project.

首先从您的项目参考中检查您的System.Web.WebPages程序集。

  1. If not found, then add by select add referencefrom project Reference.
  2. If found, any the check version from Propertiesof that reference. Then check your project web.configfile. May be this two versions are not matching.
  1. 如果未找到,则通过从项目引用中选择添加引用添加
  2. 如果找到,则来自该引用的属性的任何检查版本。然后检查您的项目web.config文件。可能是这两个版本不匹配。

For me, I add a reference of version 2.0.0.0. but my web.config file reference it from

对我来说,我添加了 2.0.0.0 版本的引用。但我的 web.config 文件从

<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />

<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />

and I change it to

我把它改成

<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />

<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />

it works for me in MVC5.

它在 MVC5 中对我有用。

Please check highlighted section in my attachment for more clearance.

请检查我的附件中突出显示的部分以获得更多许可。

System.Web.WebPages

系统.Web.网页

回答by Thach Lockevn

Go to menu: "Tools / Nuget Package Manager / Package Manager Console"

转到菜单:“工具/Nuget 包管理器/包管理器控制台”

run command install-package Microsoft.AspNet.WebPages

运行命令 install-package Microsoft.AspNet.WebPages