I'm using FluentValidation in my project. There is an issue that the Must
clause is ignoring the When
clause. Below is a code sample.
RuleFor(model => model.Field)
.Must(somePredicate)
.When(conditionToRunValidation)
But the Must
clause ignores the When
and gives error even when the conditionToRunValidation
is false
.
I'd be grateful for any sort of guidance to solve this issue.
This code seems to work, so probably your condition is not false
. You should try debugging your code and check if conditionToRunValidation
really is false
, or post more of your code, where you set the value of it.