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运行时:
> FluentValidation v3.0.0.0
> Microsoft.VisualStudio.QualityTools.UnitTestFramework v10.0.0.0
>系统
> System.Core
其他一些观点:
>没有调试器运行测试工作正常
>代码覆盖率已关闭
>我已将引用的程序集最小化
>我在Fusion日志中看不到任何错误
>我尝试应用answer to a similar question中的SecurityRulesAttribute
>我在VerificationException and testing的博客文章中尝试了一些东西
>在MSTest和Resharper主机下发生(没有尝试过NUnit,因为通用线程似乎是’在调试器下’.
>以管理员身份或非管理员身份运行VS时发生
有谁知道如何防止这种VerificationException,解决它,和/或它为什么会被造成?似乎有这么少的装配,不应该有任何冲突的装载.我还将FluentValidation卫星程序集移开了,但仍然得到了异常.
解决方法
要防止出现此问题,您必须在Visual Studio 2010 Ultimate中禁用IntelliTrace,或者必须将FluentValidation添加到IntelliTrace应从收集数据中排除的模块列表中.我的网络搜索似乎表明它是一个IntelliTrace错误. blog post在blog post中说:
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.
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检测错误.
无论如何,这是如何解决问题:
>在VS中,选择Debug |选项和设置… | IntelliTrace |模块>在以下对话框中,单击“添加…”,然后在文本框中输入FluentValidation.