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
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:
Some other points:
SecurityRulesAttribute
from the answer to a similar question
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.
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.
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:
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.
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:
I experienced the same issue and found TypeMock 6.0 to be the culprit. By disabling TypeMock Isolator (menu TypeMock -> Disable TypeMock Isolator) I got rid of the problem. This of course breaks any TypeMock dependent test.
Note that adding FluentValidation to IntelliTrace exceptions does not resolve the issue when TypeMock is the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With