Skip to content

Wrapping a call to RuleForEach with WhenAsync will trigger a AsyncValidatorInvokedSynchronouslyException even when calling `ValidateAsync. #1955

@JeremySkinner

Description

@JeremySkinner

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. 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions