The class constructor throws a VerificationException after upgrading to VS 2012 and .Net 4.5

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); } } 

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.

+6
source share
2 answers

It appears that the command offered by the CLR team is specifically defined :

Fixed .net 4.5 reflection bug Applied the fix proposed by the CLR team to AbstractValidator and DelegateValidator.

https://github.com/thecodejunkie/FluentValidation/commit/ddc1d7235b9c122c06fd224e8490b94791a715c0

+5
source

We had the same problem in my work today when testing the upgrade to RTM version VS2012 and using the FluentValidation package.

The solution we are currently using adds the following to 'src / CommonAssemblyInfo.cs' in the FluentValidation src and restores it:

 [assembly: SecurityRules(SecurityRuleSet.Level1, SkipVerificationInFullTrust = true)] 

Join the discussion: http://fluentvalidation.codeplex.com/discussions/391890

+3
source

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


All Articles