我使用的是 FluentValidation 3.4.6,我的项目的目标框架是 .net 4。我已经彻底检查了我的解决方案,以确保没有对旧版本的 FluentValidation 的引用。
我相信这个版本的 FluentValidation 可以解决 .NET 4.5 中引入的反射错误,但是我仍然收到 VerificationException,如此处所述http://elegantcode.com/2012/08/23/net-4 -5-操作-可能会破坏运行时的稳定性-yikes/
此时抛出 VerificationException:
MyValidator : AbstractValidator<MyObj>
ctor {
RuleFor(x => x.SomeProperty).Equal(true);
}
at FluentValidation.Resources.LocalizedStringSource.CreateFromExpression(Expression`1 expression, IResourceAccessorBuilder resourceProviderSelectionStrategy) in c:\projects\FluentValidation\src\FluentValidation\Resources\LocalizedStringSource.cs:line 66
at FluentValidation.Validators.PropertyValidator..ctor(Expression`1 errorMessageResourceSelector) in c:\projects\FluentValidation\src\FluentValidation\Validators\PropertyValidator.cs:line 46
at FluentValidation.Validators.EqualValidator..ctor(Object valueToCompare, IEqualityComparer comparer) in c:\projects\FluentValidation\src\FluentValidation\Validators\EqualValidator.cs:line 37
at FluentValidation.DefaultValidatorExtensions.Equal[T,TProperty](IRuleBuilder`2 ruleBuilder, TProperty toCompare, IEqualityComparer comparer) in c:\projects\FluentValidation\src\FluentValidation\DefaultValidatorExtensions.cs:line 143
at MyValidator..ctor() in MyValidator.cs:line 22