You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#2097 (Fix for multi-level child-rules) broke our validation code. We get exception Unable to cast object of type FluentValidation.Internal.RuleBuilder2[Root, Bar] to type FluentValidation.Internal.RuleBuilder2[Root, Base] when setting up validation in sample below.
It worked with 11.5.1, but broke when we upgraded to 11.7.1
Steps to Reproduce
using FluentValidation;
public class Root
{
public Bar Data {get; set;} = null;
}
public class Base
{
public int Value {get; set;}
}
public class Bar : Base
{
public int BarValue {get; set;}
}
public class RootValidator : AbstractionValidator<Root>
{
public RootValidator()
{
RuleFor(x => x).ChildRules(RootRules);
}
public static Action<InlineValidator<Base>> BaseRules()
{
return rules => {
rules.RuleFor(x => x.Value).NotEqual(-1);
};
}
public static Action<InlineValidator<Root>> RootRules()
{
return rules => {
rules.RuleFor(x => x.Data).ChildRules(BaseRules());
};
}
}
public static class Program
{
public static void Main()
{
var validator = new RootValidator();
var result = validator.Valdiate(new Root());
}
}
The text was updated successfully, but these errors were encountered:
We have worked around it for now, by being more explicit about types in the various rule-builders (either just using the most specific type or using constrained generics). But is very troublesome that this causes runtime exceptions instead compile-time errors.
FluentValidation version
11.7.1
ASP.NET version
No response
Summary
#2097 (Fix for multi-level child-rules) broke our validation code. We get exception
Unable to cast object of type FluentValidation.Internal.RuleBuilder2[Root, Bar] to type FluentValidation.Internal.RuleBuilder2[Root, Base]
when setting up validation in sample below.It worked with 11.5.1, but broke when we upgraded to 11.7.1
Steps to Reproduce
The text was updated successfully, but these errors were encountered: