I have a View Model class in a WPF application that has some very complex validation. I have implemented the IValidatableObject interface to provide the custom validation logic. The problem is that my IEnumerable<ValidationResult> Validate(ValidationContext validationContext) is never called!
Here is the code attempting the validation:
Validator.TryValidateObject(RMA, new ValidationContext(RMA, null, null), result);
Any ideas why the Validator object is not calling my custom validation code?
The problem was that I was I had
[Required]on one of the fields in the custom class and theValidatorwill not perform custom validation until all data annotation validation has been completed. Removing the[Required]allows the custom validation to execute.EDIT:When validating an object, the following process is applied in Validator.ValidateObject:
IValidatableObject, then call its Validate method and return any failure(s)http://jeffhandley.com/archive/2009/10/16/validator.aspx
Validation will abort at step #2.