Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@JeremySkinner

Description

@JeremySkinner
Issue body actions

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.