Whenever I run any of the following unit test with an attached debugger, I get a VerificationException inside the FluentValidation code at this point (after that it will display the whole stack later):
at FluentValidation.Resources.LocalizedStringSource.CreateFromExpression(Expression`1 expression, IResourceAccessorBuilder resourceProviderSelectionStrategy) in ...\FluentValidation\Resources\LocalizedStringSource.cs:line 66
Tests:
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 referenced only these assemblies in a one-time, single-project script that targets the runtime 4.0.30319:
- FluentValidation v3.0.0.0
- Microsoft.VisualStudio.QualityTools.UnitTestFramework v10.0.0.0
- System
- System.Core
Some other points:
- Running a test without debugging works fine
- Code Coverage Disabled
- I minimized reference assemblies to a minimum
- I do not see errors in the Fusion log
- I tried applying
SecurityRulesAttribute from an answer to a similar question - I tried some things from a blog post on VerificationException and testing
- It occurs with both MSTest hosts and Resharper (I have not tried NUnit, because the general thread seems to be "under the debugger".
- Occurs when VS starts as admin or non-admin
Does anyone know how I can prevent this VerificationException from working around it and / or why it is called? It seems that with so many assemblies there should be no conflicting loads. I also moved the FluentValidation satellite assemblies out of the way, but still get an exception.
source share