[英]How can I prevent a VerificationException when running a test with attached debugger?
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): 每当我运行附加调试器的以下任一单元测试时,此时我在FluentValidation代码中得到一个
VerificationException
(如果需要,稍后将发布整个堆栈跟踪 ):
at FluentValidation.Resources.LocalizedStringSource.CreateFromExpression(Expression`1 expression, IResourceAccessorBuilder resourceProviderSelectionStrategy)
in ...\FluentValidation\Resources\LocalizedStringSource.cs:line 66
The tests are: 测试是:
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; }
}
I've referenced just these assemblies in a single-solution, single-project scenario, targeting the 4.0.30319 runtime: 我在单一解决方案,单项目场景中引用了这些程序集,目标是4.0.30319运行时:
Some other points: 其他一些观点:
SecurityRulesAttribute
from the answer to a similar question SecurityRulesAttribute
应用于类似的问题 Does anyone know how I can prevent this VerificationException
, work around it, and/or why it's being caused? 有谁知道如何防止这种
VerificationException
,解决它,和/或它为什么会被造成? 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.
我还将FluentValidation卫星程序集移开了,但仍然得到了异常。
Ok, I've got it. 好的,我知道了。 First I'd like to acknowledge Jeremy Skinner for working with me to reproduce the problem.
首先,我要感谢Jeremy Skinner 与我一起重现这个问题。 His help spurred me to try tweaking my environment further.
他的帮助促使我尝试进一步调整我的环境。
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. 要防止出现此问题,您必须在Visual Studio 2010 Ultimate中禁用IntelliTrace ,或者必须将FluentValidation添加到IntelliTrace应从收集数据中排除的模块列表中。 My web searches seem to indicate it's an IntelliTrace bug.
我的网络搜索似乎表明它是一个IntelliTrace错误。 Jim Nakashima in his blog post says:
Jim Nakashima在他的博客文章中说:
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.
问题是IntelliTrace本身有一个错误,当IntelliTrace集合设置为“高”(这是Cloud IntelliTrace场景中的默认值)时,标记为SecurityTransparent的程序集中具有boolean out参数的方法将失败。
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.
如果您的方法的签名包含布尔输出参数并且您已将程序集安全性设置为SecurityTransparent,您将在自己的代码中看到这一点。
I looked at my stack trace and briefly through the FluentValidation source, but didn't see this. 我查看了我的堆栈跟踪并简要介绍了FluentValidation源代码,但没有看到这一点。 I suspect it might be a similar IntelliTrace instrumentation bug relating to LINQ expressions.
我怀疑它可能是与LINQ表达式相关的类似IntelliTrace检测错误。
Anyway, here's how to fix the issue: 无论如何,这是如何解决问题:
I experienced the same issue and found TypeMock 6.0 to be the culprit. 我遇到了同样的问题,发现TypeMock 6.0是罪魁祸首。 By disabling TypeMock Isolator (menu TypeMock -> Disable TypeMock Isolator) I got rid of the problem.
通过禁用TypeMock Isolator(菜单TypeMock - >禁用TypeMock Isolator)我摆脱了问题。 This of course breaks any TypeMock dependent test.
这当然会破坏任何与TypeMock相关的测试。
Note that adding FluentValidation to IntelliTrace exceptions does not resolve the issue when TypeMock is the problem. 请注意,当TypeMock出现问题时,将FluentValidation添加到IntelliTrace异常并不能解决问题。
In my case my Asp.net MVC 3 application had a reference to FluentValidation.dll and FluentValidation.mvc.dll files. 在我的情况下,我的Asp.net MVC 3应用程序引用了FluentValidation.dll和FluentValidation.mvc.dll文件。
I removed the references and installed the FluentValidation for MVC 3 using nuget package manager and It worked. 我删除了引用并使用nuget包管理器安装了FluentValidation for MVC 3并且它工作正常。
It downloaded FluentValidation.Mvc version 5.0.0.1 它下载了FluentValidation.Mvc版本5.0.0.1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.