FluentValidation version
11.0.2
ASP.NET version
No response
Summary
Wrapping a call to RuleForEach with WhenAsync will trigger a AsyncValidatorInvokedSynchronouslyException even when calling ValidateAsync.
The AsyncValidatorInvokedSynchronouslyException should only be thrown when calling Validate, never ValidateAsync.
Steps to Reproduce
class MyValidator : AbstractValidator<Person> {
public MyValidator() {
WhenAsync((x, cancel) => x.Id > 0, () => {
RuleForEach(x => x.Nicknames).NotNull();
});
}
}
class Person {
public int Id { get; set; }
public string[] Nicknames { get; set; }
}
var validator = new MyValidator();
await validator.ValidateAsync(new Person());
// Incorrectly throws a AsyncValidatorInvokedSynchronouslyException even though it was invoked asynchronously.