【问题标题】:The type 'ModelClientValidationRule' exists in both dlls两个 dll 中都存在“ModelClientValidationRule”类型
【发布时间】:2013-01-20 12:45:13
【问题描述】:

我下载了example written in asp.net mvc3 visual studio 2010的源码

通过 visual studio 2012 打开解决方案文件。它将源代码转换为 2012 并打开解决方案。

当我构建解决方案时出现错误:

错误 1 ​​类型“System.Web.Mvc.ModelClientValidationRule”存在于 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll' 和 'c:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\System.Web.WebPages.dll' C:\studyCode\MVCDemo-Part12\MVCDemo-Part12\MVCDemo\Attributes\Validation\EqualAttribute.cs 54 28 MVCDemo

【问题讨论】:

标签: asp.net asp.net-mvc asp.net-mvc-3 visual-studio-2010 visual-studio-2012


【解决方案1】:

只需从解决方案参考中删除 System.Web.WebPages

【讨论】:

  • +1 为简单起见。通常如果你有这两个参考,一个是错误的。如果你在 MVC 中工作,System.Web.WebPages 是多余的。
  • 或者,如果您碰巧在 System.Web.WebPages 程序集中使用了某些东西,例如 TagBuilder,则将引用更改为 v1 而不是 v2,因为 v2 包含冲突的 ModelClientValidationRule 类。
【解决方案2】:

这个答案也可能解决你的问题:

  1. 在根 Web.config 文件中,使用键 webPages:Version 和值 1.0.0.0 添加一个新条目。

    <appSettings>
    <add key="webpages:Version" value="1.0.0.0"/>
    <add key="webpages:Version" value="1.0.0.0"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
    </appSettings>
    

2.In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.

3.Locate the following assembly references:

    <Reference Include="System.Web.WebPages"/>
    <Reference Include="System.Web.Helpers" />

将它们替换为以下内容:

<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>
<Reference Include="System.Web.Helpers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/>

4.保存更改,关闭您正在编辑的项目 (.csproj) 文件,然后右键单击该项目并选择重新加载。

参考:http://forums.asp.net/t/1723108.aspx/1

也可以试试:http://www.asp.net/learn/whitepapers/mvc4-release-notes#_Toc303253815

或者你也可以试试这个

编辑:

ProjectName.csproj

改变

<Reference Include="System.Web.WebPages"/> 

<Reference Include="System.Web.WebPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/><br/><br/>

注意:此QUESTION

【讨论】:

    【解决方案3】:

    在VS2010中右键项目名称。 单击“添加可部署的依赖项”。 重建

    【讨论】:

      【解决方案4】:

      http://www.asp.net/whitepapers/mvc4-release-notes

      从 MVC 3 升级到 MVC 4 时,请参阅此链接,其中包含已知错误:

      按照步骤操作,您应该会在几分钟内启动并运行。

      仅供参考 - 如果您从网上下载了一个 zip 文件,请右键单击该文件,单击“属性”并在解压缩之前选择“取消阻止”,否则您会感到痛苦。

      我添加了 Notes -- 其余部分来自上面引用的站点,在从 MVC3 升级到 4 时存在已知错误:

      ***自动升级*** 将 ASP.NET MVC 3 项目升级到 ASP.NET MVC 4 ASP.NET MVC 4 可以与 ASP.NET MVC 3 并排安装在同一台计算机上,这使您可以灵活地选择何时将 ASP.NET MVC 3 应用程序升级到 ASP.NET MVC 4。

      最简单的升级方法是创建一个新的 ASP.NET MVC 4 项目并将现有 MVC 3 项目中的所有视图、控制器、代码和内容文件复制到新项目中,然后更新程序集引用匹配任何非 MVC 模板的新项目包含您正在使用的程序集。如果您对 MVC 3 项目中的 Web.config 文件进行了更改,则还必须将这些更改合并到 MVC 4 项目中的 Web.config 文件中。

      ***手动升级****** 要将现有的 ASP.NET MVC 3 应用程序手动升级到版本 4,请执行以下操作:

      在项目的所有 Web.config 文件中(项目根目录中有一个,Views 文件夹中有一个,项目中每个区域的 Views 文件夹中有一个),替换以下文本的每个实例(注意:在使用 Visual Studio 2012 创建的项目中找不到 System.Web.WebPages,Version=1.0.0.0): System.Web.Mvc,版本=3.0.0.0 System.Web.WebPages,版本=1.0.0.0 System.Web.Helpers,版本=1.0.0.0 System.Web.WebPages.Razor,版本=1.0.0.0

      带有以下相应的文字:

      System.Web.Mvc, Version=4.0.0.0
      System.Web.WebPages, Version=2.0.0.0
      System.Web.Helpers, Version=2.0.0.0
      System.Web.WebPages.Razor, Version=2.0.0.0
      

      注意 - “webpages:Version”根本不在我的设置中...我只添加了“PreserveLoginUrl”行*

      在根 Web.config 文件中,将 webPages:Version 元素更新为“2.0.0.0”并添加一个值为“true”的新 PreserveLoginUrl 键:

      在解决方案资源管理器中,右键单击引用并选择管理 NuGet 包。在左侧窗格中,选择 Online\NuGet 官方包源,然后更新以下内容: ASP.NET MVC 4 (可选)jQuery、jQuery 验证和 jQuery UI (可选)实体框架 (可选)Modernizr

      这是我要让它工作的版本……**

      在解决方案资源管理器中,右键单击项目名称,然后选择卸载项目。然后再次右键单击该名称并选择 Edit ProjectName.csproj。 找到 ProjectTypeGuids 元素并将 {E53F8FEA-EAE0-44A6-8774-FFD645390401} 替换为 {E3E379DF-F4C6-4180-9B81-6769533ABE47}。 保存更改,关闭您正在编辑的项目 (.csproj) 文件,右键单击该项目,然后选择重新加载项目。 如果项目引用了使用以前版本的 ASP.NET MVC 编译的任何第三方库,请打开根 Web.config 文件并在配置部分下添加以下三个 bindingRedirect 元素:

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

      快乐编码

      丹 B.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-07-30
        • 1970-01-01
        • 1970-01-01
        • 2012-05-16
        • 2011-11-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多