将混合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中删除其引用。但是,这一切都没有起作用。

有任何想法吗?

有帮助吗?

解决方案

确保您在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 2即使MVC 1在机器上。

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

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

其他提示

我遇到了类似的东西,解决方案是更改对Microsoft.web.mvc的引用,因此复制本地设置为true。

我有相同的错误,并单击页面中的详细编译错误链接显示出与 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 元素。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top