How can I prevent a VerificationException when running a test with an attached debugger?

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.

+6
source share
3 answers

Ok, I have it. First, I would like to confirm Jeremy Skinner is working with me to reproduce the problem. His help pushed me to further improve the environment.

To prevent the problem, you either need to disable IntelliTrace in Visual Studio 2010 Ultimate, or you need to add FluentValidation to the list of modules that IntelliTrace should exclude from data collection. My internet search seems to indicate an IntelliTrace error. Jim Nakashima in his blog post says:

The problem is that IntelliTrace itself has an error when methods that have the boolean out parameter in the assembly that is marked as SecurityTransparent do not work if the IntelliTrace collection is set to high, which is the default value in the Cloud IntelliTrace script.

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

I looked at the trace of my stack and briefly through the FluentValidation source, but did not see it. I suspect this could be a similar IntelliTrace toolkit error related to LINQ expressions.

In any case, how to solve the problem:

  • In VS, select Debug | Parameters and settings ... | IntelliTrace | Modules
  • In the next dialog box, click Add ... and enter FluentValidation in the text box.

enter image description here

+12
source

I ran into the same problem and found that TypeMock 6.0 is the culprit. By disconnecting the TypeMock isolator (TypeMock menu → Disable TypeMock Isolator), I got rid of this problem. This, of course, breaks any type-specific test.

Please note that adding FluentValidation to IntelliTrace exceptions does not resolve the issue when the TypeMock issue is a problem.

+1
source

In my case, the Asp.net MVC 3 application had a link to the files FluentValidation.dll and FluentValidation.mvc.dll.

I removed the links and installed FluentValidation for MVC 3 using the nuget package manager and it worked.

Downloaded FluentValidation.Mvc version 5.0.0.1

0
source

Source: https://habr.com/ru/post/893687/


All Articles