类型或命名空间名称“Mvc”;命名空间“System.Web”中不存在

发布于 2024-08-30 05:43:52 字数 568 浏览 3 评论 0原文

将混合 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

压抑⊿情绪 2024-09-06 05:43:52

确保您的 Web.config 中有绑定重定向:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Web.Mvc" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

即使机器上有 MVC 1,这也会强制使用 MVC 2。

另外:MVC 1 确实有一个 System.Web.Mvc 命名空间,因此请确保您还拥有:

  <assemblies>
    <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

Make sure you have the binding redirect in your Web.config:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Web.Mvc" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

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:

  <assemblies>
    <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
一腔孤↑勇 2024-09-06 05:43:52

我遇到了类似的情况,解决方案是更改对 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.

时光无声 2024-09-06 05:43:52

我遇到了同样的错误,单击页面中的详细编译错误链接显示了 System.Web.Helpers.Http、.WebPages 的问题>。

备份系统后,我运行了“update-package -reinstall”并强制卸载/重新安装所有软件包。这迫使 web.config 文件被正确重建,并且 dependentAssembly 部分被正确构建。

重建解决方案后,它第一次运行。

请注意,它确实将以下错误的 providers 部分添加到 web.config 中。

<contexts>
  <context type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</contexts>
<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>

这只会生成一个构建警告,但我确实删除了它以支持前面的 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 the dependentAssembly 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.

<contexts>
  <context type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</contexts>
<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>

This only generates a build warning, but I did remove it in favor of the preceeding contexts element.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文