类型或命名空间名称“Mvc”;命名空间“System.Web”中不存在
将混合 ASP.NET MVC1 应用程序转换为 MVC2 后,当我尝试运行该应用程序时,出现以下错误:
命名空间“System.Web”中不存在类型或命名空间名称“Mvc”(您是否缺少程序集引用?)
web.config 文件中所谓的罪魁祸首是 System.Web.Mvc:
<namespaces>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
到目前为止,我的调查似乎使我相信 System.Web.Mvc 的版本 2 尚未安装或尚未被选中。
我尝试创建一个文件>基于 MVC 2 的新项目,并且采用了新的 (v2) 版本的 MVC。我还转换了一些其他项目(不是混合项目),它们已经毫无问题地转换为 MVC2。
我还卸载了 MVC1,尝试从 GAC 中删除对它的引用。然而,这一切都没有奏效。
有什么想法吗?
After converting a Hybrid ASP.NET MVC1 app to MVC2 I'm getting the following error when I try and run the application:
The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
The allegeded culprit in the web.config file is System.Web.Mvc:
<namespaces>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Web.Mvc.Html"/>
So far my investigation seems to lead me to believe that version 2 of System.Web.Mvc is not installed or has not been picked up.
I've tried creating a File > New Project based on MVC 2 and that's picking up the new (v2) version of MVC. I've also converted some other projects (that were not hybrids) and they've converted without problem to MVC2.
I've also uninstalled MVC1 to try and remove references to it from the GAC. However, none of this has worked.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保您的 Web.config 中有绑定重定向:
即使机器上有 MVC 1,这也会强制使用 MVC 2。
另外:MVC 1 确实有一个 System.Web.Mvc 命名空间,因此请确保您还拥有:
Make sure you have the binding redirect in your Web.config:
This forces MVC 2 even if MVC 1 is on the machine.
Also: MVC 1 does have a
System.Web.Mvc
namespace, so make sure you also have:我遇到了类似的情况,解决方案是更改对 Microsoft.Web.Mvc 的引用,以便 Copy Local 设置为 True。
I came across somthing similar and the solution was to change the reference to Microsoft.Web.Mvc so Copy Local was set to True.
我遇到了同样的错误,单击页面中的详细编译错误链接显示了
System.Web.Helpers
、.Http、
和.WebPages
的问题>。备份系统后,我运行了“update-package -reinstall”并强制卸载/重新安装所有软件包。这迫使 web.config 文件被正确重建,并且
dependentAssembly
部分被正确构建。重建解决方案后,它第一次运行。
请注意,它确实将以下错误的
providers
部分添加到 web.config 中。这只会生成一个构建警告,但我确实删除了它以支持前面的
contexts
元素。I had the same error and clicking the detailed compilation error link in the page showed problems with
System.Web.Helpers
,.Http,
and.WebPages
.After backing up the system I ran
update-package -reinstall
' and forced an uninstall/reinstall of all packages. This forced the web.config file to be rebuilt correctly and thedependentAssembly
sections were constructed right.After rebuilding the solution it ran first time.
Note, it did add the following bad
providers
section to the web.config.This only generates a build warning, but I did remove it in favor of the preceeding
contexts
element.