I have code like
using FluentValidation;
public class FreeformValidator : AbstractValidator<Freeform>
{
public FreeformValidator() // <-- VerificationException on this line
{
RuleFor(ff => ff.Text).Must(BeLongEnough).WithMessage("Must be at least {0} characters.", ff => ff.MinLength);
}
}
that is run by a unit test. Under VS 2010 targeting .Net 4, the unit test ran fine. After updating to VS 2012 and targeting .Net 4.5, the unit test throws
VerificationException
Operation could destabilize the runtime.
The exception dialog suggests
Make sure your application is not loading two conflicting versions of a class library.
AbstractValidator is from FluentValidation. Both the project being tested and the unit test project reference FluentValidation 3.3.1.0. Both projects also now target .Net 4.5.
Both projects target AnyCPU. The code is running on Windows 7 64-bit.
Update
Here is the unit test code
[TestMethod]
public void FreeformValidation_MinLength()
{
Freeform fa = new Freeform();
fa.Required = true;
fa.MinLength = 3;
fa.MaxLength = 10;
FreeformValidator fv = new FreeformValidator();
fa.Text = "AB";
ValidationResult results = fv.Validate(fa);
Assert.AreEqual(1, results.Errors.Count, "Expected MinLength to fail.");
Assert.AreEqual("Must be at least 3 characters.", results.Errors[0].ErrorMessage, "Expected MinLength to fail.");
}
Update 2
Possibly related
System.Security.VerificationException after installation VS 2012
However, switching the configuration to x86 and re-running the tests results in the same Exception.
Similar issues that don't appear to apply
How can I prevent a VerificationException when running a test with attached debugger?
Unit test fails the same way without debugger, and adding FluentValidator to IntelliTrace exclusion list did not help.
Operation could destabilize the runtime?
I do not have a strongly named assembly, and no AllowPartiallyTrustedCallers attribute.
Update 3
PEVerify finds no problems with either the test project's DLL, or the DLL being tested.