Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JeremySkinner opened this issue Jun 10, 2022 · 1 comment
Milestone

Comments

@JeremySkinner
Copy link
Member

JeremySkinner commented Jun 10, 2022

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. 
@JeremySkinner JeremySkinner added this to the 11.0.3 milestone Jun 10, 2022
@JeremySkinner
Copy link
Member Author

Fixed in 11.0.3

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant