I have code like
using FluentValidation; public class FreeformValidator : AbstractValidator<Freeform> { public FreeformValidator()
which runs a unit test. In VS 2010 focused on .Net 4, the unit test worked fine. After upgrading to VS 2012 and targeting .Net 4.5 unit test throws
VerificationException
An operation can destabilize runtime.
Exclusion Dialog Offers
Make sure your application does not load two conflicting versions of the class library.
AbstractValidator is a FluentValidation. Both the test project and the unit test guide FluentValidation 3.3.1.0. Both projects are also now targeting .Net 4.5.
Both projects target AnyCPU. The code runs on a 64-bit version of Windows 7.
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 installing VS 2012
However, switching the configuration to x86 and re-running the test results in the same Exception.
Similar issues that do not seem to apply
How to prevent VerificationException when running a test with an attached debugger?
Unit test does not work the same without a debugger, and adding a FluentValidator to the IntelliTrace exception list did not help.
Can an operation destabilize runtime?
I do not have a strongly named assembly and the AllowPartiallyTrustedCallers attribute.
Update 3
PEVerify does not detect problems with either the test project DLL or the tested DLL.