Skip to content

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

Closed
@JeremySkinner

Description

@JeremySkinner
Member

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. 

Activity

added this to the 11.0.3 milestone on Jun 10, 2022
JeremySkinner

JeremySkinner commented on Jun 10, 2022

@JeremySkinner
MemberAuthor

Fixed in 11.0.3

locked as resolved and limited conversation to collaborators on Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @JeremySkinner

        Issue actions

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