You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a hierarchy of classes. They use validators with Include to include base class validator.
I'm trying to validate only one field by using ValidationContext with MemberNameValidatorSelector.
For base class it works as expected, for inheritor validation returns errors for different fields, not included in MemberNameValidatorSelector.
When calling validation for FooString property of Bar:
Barbar=new Bar(){FooString="NotEmpty"};varproperties=new[]{ nameof(Bar.FooString)};varcontext=newValidationContext<Bar>(bar,new PropertyChain(),new MemberNameValidatorSelector(properties));IValidatorv=new BarValidator();varresult= v.Validate(context);// result.Errors is empty
result has no errors as expected.
But with the same code for FooString property of Baz:
Bazbaz=new Baz(){FooString="NotEmpty"};varproperties=new[]{ nameof(Baz.FooString)};varcontext=newValidationContext<Baz>(baz,new PropertyChain(),new MemberNameValidatorSelector(properties));IValidatorv=new BazValidator();varresult= v.Validate(context);// result.Errors has an error for FooList
result has an error for FooList, even thought it is not included in properties.
The text was updated successfully, but these errors were encountered:
This is happening because of the nested calls to Include. The state key that tracks whether an Include rule should be considered by the MemberNameValidatorSelector was being cleared too early. Fixed in 41ca856
I've pushed out the 11.2.0 release to Nuget which includes this fix.
FluentValidation version
11.1.1
ASP.NET version
6.0
Summary
There is a hierarchy of classes. They use validators with
Include
to include base class validator.I'm trying to validate only one field by using
ValidationContext
withMemberNameValidatorSelector
.For base class it works as expected, for inheritor validation returns errors for different fields, not included in
MemberNameValidatorSelector
.Steps to Reproduce
You can try out a demo on dotnetfiddle.
A hierarchy of classes :
Validators:
When calling validation for
FooString
property ofBar
:result
has no errors as expected.But with the same code for
FooString
property ofBaz
:result
has an error forFooList
, even thought it is not included inproperties
.The text was updated successfully, but these errors were encountered: