当使用附加的调试器运行测试时,如何防止VerificationException? [英] How can I prevent a VerificationException when running a test with attached debugger?

查看:323
本文介绍了当使用附加的调试器运行测试时,如何防止VerificationException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我运行以下任一单元测试,附带一个调试器时,我会在 VerificationException rel =noreferrer> FluentValidation 代码在这一点上(如果需要,将在后面发布整个堆栈跟踪):

Whenever I run either of the following unit test with a debugger attached, I get a VerificationException inside FluentValidation code at this point (will post whole stacktrace later if necessary):

at FluentValidation.Resources.LocalizedStringSource.CreateFromExpression(Expression`1 expression, IResourceAccessorBuilder resourceProviderSelectionStrategy)
in ...\FluentValidation\Resources\LocalizedStringSource.cs:line 66

测试是:

using FluentValidation;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestMethod1()
    {
        var c = new MyClass();
        var v = new MyValidator();
        v.Validate(c);
    }

    [TestMethod]
    public void TestMethod2()
    {
        Exception ex = null;
        var done = new ManualResetEvent(false);
        ThreadPool.QueueUserWorkItem(
            o =>
            {
                try
                {
                    TestMethod1();
                }
                catch (Exception e)
                {
                    ex = e;
                }
                finally
                {
                    done.Set();
                }
            });

        done.WaitOne();
        Assert.IsNull(ex);
    }
}

public class MyValidator : AbstractValidator<MyClass>
{
    public MyValidator()
    {
        RuleFor(c => c.MyProperty).GreaterThan(0);
    }
}

public class MyClass
{
    public int MyProperty { get; set; }
}

我已经在单一解决方案中单引号了这些程序集,针对4.0.30319运行时的项目方案:

I've referenced just these assemblies in a single-solution, single-project scenario, targeting the 4.0.30319 runtime:


  • FluentValidation v3.0.0.0

  • Microsoft .VisualStudio.QualityTools.UnitTestFramework v10.0.0.0

  • 系统

  • System.Core

  • FluentValidation v3.0.0.0
  • Microsoft.VisualStudio.QualityTools.UnitTestFramework v10.0.0.0
  • System
  • System.Core

其他一些要点:

  • Running the test without a debugger works fine
  • Code coverage is turned off
  • I've minimized the referenced assemblies down to the minimum
  • I don't see any errors in the Fusion log
  • I tried applying the SecurityRulesAttribute from the answer to a similar question
  • I tried some things from a blog post on VerificationException and testing
  • Occurs under both MSTest and Resharper hosts (haven't tried NUnit, because the common thread seems to be 'under debugger'.
  • Occurs when running VS as admin or non-admin

是否有人知道如何防止这个 VerificationException ,解决它,和/或为什么会造成这种情况?看起来这么少的程序集,不应该有任何冲突的加载。我也移动了FluentValidation的卫星组件,但仍然得到例外。

Does anyone know how I can prevent this VerificationException, work around it, and/or why it's being caused? It seems with so few assemblies, there shouldn't be any conflicting ones loading. I've also moved the FluentValidation satellite assemblies out of the way but still get the exception.

推荐答案

好吧,我已经它。首先,我要确认 Jeremy Skinner 与我合作重现问题。他的帮助促使我进一步调整我的环境。

Ok, I've got it. First I'd like to acknowledge Jeremy Skinner for working with me to reproduce the problem. His help spurred me to try tweaking my environment further.

为了防止出现此问题,您必须禁用 IntelliTrace 在Visual Studio 2010 Ultimate中,或者您必须添加 FluentValidation 到IntelliTrace应该从收集数据中排除的模块列表。我的网页搜索似乎表明它是一个IntelliTrace错误。 Jim Nakashima 在他的博客文章说:

To prevent the problem you either have to disable IntelliTrace in Visual Studio 2010 Ultimate, or you have to add FluentValidation to the list of modules that IntelliTrace should exclude from collecting data. My web searches seem to indicate it's an IntelliTrace bug. Jim Nakashima in his blog post says:


问题是IntelliTrace本身有一个错误,当IntelliTrace集合被设置时,在程序集中标记为SecurityTransparent的布尔输出参数的方法将失败到高,这是Cloud IntelliTrace方案中的默认值。

The issue is that IntelliTrace itself has a bug where methods that have a boolean out parameter in an assembly that is marked as SecurityTransparent will fail when IntelliTrace collection is set to "high" which is the default in the Cloud IntelliTrace scenario.

如果您有一个方法,其签名包括布尔输出参数,您将在自己的代码中看到这一点,您已将安装程序的安全性设置为SecurityTransparent。

You will see this in your own code if you have a method whose signature includes a boolean out parameter and you have set your assembly security to SecurityTransparent.

我查看了我的堆栈跟踪,并简要地通过FluentValidation源,但没有看到这个。我怀疑它可能是一个与LINQ表达式相关的类似的IntelliTrace工具错误。

I looked at my stack trace and briefly through the FluentValidation source, but didn't see this. I suspect it might be a similar IntelliTrace instrumentation bug relating to LINQ expressions.

无论如何,以下是解决问题的方法:

Anyway, here's how to fix the issue:


  1. 在VS中,选择调试 | 选项和设置... | IntelliTrace | 模块

  2. 在以下对话框中,单击添加... ,然后在文本框中输入FluentValidation。

  1. In VS, select Debug | Options And Settings... | IntelliTrace | Modules
  2. In the following dialog, click Add... and enter FluentValidation into the text box.

这篇关于当使用附加的调试器运行测试时,如何防止VerificationException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆