【问题标题】:Adding moles assembly for System.Data failed为 System.Data 添加痣程序集失败
【发布时间】:2013-03-06 11:42:10
【问题描述】:

我在其中一个单元测试项目(VS 2010 单元测试)中使用 Microsoft Moles Framework (x86) 版本 0.94.51023.0。为了测试应用程序中的数据访问层方法,我尝试为 System.Data.dll 添加 moles 程序集,以便可以模拟 SqlConnection 和 SqlCommand 对象。当我在添加 moles 程序集时构建单元测试时,构建失败并显示以下错误详细信息

error CS0234: The type or namespace name 'SqlCredential' does not exist in the namespace 'System.Data.SqlClient'

error CS0234: The type or namespace name 'ApplicationIntent' does not exist in the namespace 'System.Data.SqlClient'

我的构建输出窗口的结尾显示了这个:

error MSB3073: The command ""C:\Program Files (x86)\Microsoft Moles\bin\moles.exe" @...\UnitTests\obj\Debug\Moles\moles.args" exited with code -1002.

【问题讨论】:

    标签: mocking moles


    【解决方案1】:

    替换“C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework. NETFramework\v4.0”,版本为“4.0.30319.17929”,位于“C:\Windows\Microsoft.NET\Framework64\v4.0.30319”。看起来这个版本的 dll 中定义了 SqlCredential 类型,我能够成功地破坏 System.Data dll

    【讨论】:

    • 你是不是碰巧安装了VS2012和VS2010?
    • 是的,我确实安装了它们。这是否造成了这种 Dll 不匹配?
    • 是的,我相信这是导致问题的原因。
    • @ranomore .. 你说得对,谢谢!!我再次测试了相同的内容以确认 VS 2012 的安装导致了该问题。在只安装了 f/w 4.0 的机器上一切正常。安装 f/w 4.5 后,构建中断。
    • 刚试过这个,它工作,但我只安装了 VS2010。如果它破坏了其他东西,我会及时通知你。
    【解决方案2】:

    我遇到了这篇帖子http://feherzsolt.wordpress.com/2013/02/13/moles-and-net-4-5/,它似乎有正确的解决方案来解决 Moles 无法为 System.* dll 生成 moled 程序集的问题。 .Net f/w 4.0 和 4.5 安装在同一台机器上时,对于使用 4.0 dll 的项目,在 moles 文件中添加 ReflectionOnly="true" 属性,可以解决构建失败的问题。

    【讨论】:

      猜你喜欢
      • 2014-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-11
      • 2012-07-23
      • 2016-12-29
      • 2012-06-15
      • 1970-01-01
      相关资源
      最近更新 更多