This project has moved and is read-only. For the latest updates, please go here.


OverridePropertyName is ignored in ValidationResult.PropertyName path when used with SetValidator and SetCollectionValidator


ValidationResult.PropertyName is generally affected by .OverridePropertyName, except when used with a navigation property with a sub-validator set. In these cases, the first portion of the ValidationResult.PropertyName path still matches the navigation property name, indexed in the case of a collection.

For example:
RuleFor(ow => ow.FineComponentCollection)
    .Must((ow, coll) => coll.Any(fc => fc.Amount > 0))
    .When(ow => ow.FineComponentCollection.Count > 0)
    .OverridePropertyName("Test") // this works
    .WithMessage("At least one non-zero monetary amount must be specified.");

RuleFor(ow => ow.FineComponentCollection)
    .OverridePropertyName("Test"); // this doesn't work
In the latter case, my ValidationResult.PropertyName still ends up as something like "FineComponentCollection[2].Amount" instead of "Test[2].Amount".
Closed Apr 23, 2013 at 2:14 PM by JeremyS


JeremyS wrote Mar 14, 2013 at 10:18 AM

Thanks for reporting this, I've fixed it in the latest commit.

user94857 wrote Jul 10, 2014 at 7:54 AM

Hey there, I'm running FluentValidation.WebAPI version 5.4 and I think this problem has resurfaced.


RuleFor(x => x.TestList).SetCollectionValidator(new RegisterTestValidator()).OverridePropertyName("testing") //doesn't work