dotnet-starter-kit icon indicating copy to clipboard operation
dotnet-starter-kit copied to clipboard

Can't use async in request validators with latest version of FluentValidations

Open dsolteszopyn opened this issue 3 years ago • 5 comments

Validator "CreateUserRequestValidator" can't be used with ASP.NET automatic validation as it contains asynchronous rules. ASP.NET's validation pipeline is not asynchronous and can't invoke asynchronous rules. Remove the asynchronous rules in order for this validator to run.

Steps to reproduce the behavior:

  1. save a new user

Expected behavior Validation should be successful if all rules are met.

dsolteszopyn avatar Nov 14 '22 15:11 dsolteszopyn

Hi @dsolteszopyn ,

You've probably updated to FluentValidation version 11.x, where they throwing exceptions if validation is integrated with ASP.NET. Check docs

You need to use FluentValidation version 10.x, for it to work with Async methods.

If this PR gets merged, using Async methods will work, because Validation will be triggered by MediatR...

For now try to use FluentValidation version 10, or move validation to a MediatR's pipeline behavior as shown in mentioned PR.

I updated my code to use the new pattern, works as expected now :)


From: Martin Arapović @.> Sent: Tuesday, November 15, 2022 10:35:42 AM To: fullstackhero/dotnet-webapi-boilerplate @.> Cc: Soltesz, Danny @.>; Mention @.> Subject: Re: [fullstackhero/dotnet-webapi-boilerplate] Can't use async in request validators with latest version of FluentValidations (Issue #799)

[CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe]

Hi @dsolteszopynhttps://protect-us.mimecast.com/s/lmjbCG62OqtqAnBfQ4fZD?domain=github.com ,

You've probably updated to FluentValidation version 11.x, where they throwing exceptions if validation is integrated with ASP.NET. Check docshttps://protect-us.mimecast.com/s/B3syCBB2J0fA8qDtzoy-n?domain=docs.fluentvalidation.net

You need to use FluentValidation version 10.x, for it to work with Async methods.

If this PRhttps://protect-us.mimecast.com/s/U5oyCDk2LnTM3poi59vzr?domain=github.com gets merged, using Async methods will work, because Validation will be triggered by MediatR...

For now try to use FluentValidation version 10, or move validation to a MediatR's pipeline behavior as shown in mentioned PRhttps://protect-us.mimecast.com/s/U5oyCDk2LnTM3poi59vzr?domain=github.com.

— Reply to this email directly, view it on GitHubhttps://protect-us.mimecast.com/s/3tSJCER2Motnpylip_-0_?domain=github.com, or unsubscribehttps://protect-us.mimecast.com/s/YDTyCJ62gwtyKOBHva4l4?domain=github.com. You are receiving this because you were mentioned.Message ID: @.***>

dsolteszopyn avatar Nov 15 '22 15:11 dsolteszopyn

@martin-arapovic-typeqast

Is this issue resolved ? I'm also facing same exception.

Do I need to downgrade to 10.4.0 from 11.2.2

xts-velkumars avatar Jan 10 '23 18:01 xts-velkumars

you either need to downgrade or update your code based upon the PR mentioned above

dsolteszopyn avatar Jan 10 '23 18:01 dsolteszopyn

Thank you @dsolteszopyn,

Its working as excepted after I changed my code.

Can we excepts async validators in futures release ?

xts-velkumars avatar Jan 10 '23 18:01 xts-velkumars