Validator.tryvalidateobject Always Returns True
28.08.2019
72 - Comments
- Validator.tryvalidateobject Always Returns True Story
- Validator.tryvalidateobject Always Returns True Value
Apr 05, 2018 I converted my public fields to properties and I am still not getting validation errors when properties marked as required are null. I am wondering what else might be short-circuiting the validation. The check is being hit, but the result is always true (valid). – Joey Morgan Apr 2 '18 at 1:37.
I am writing a simple model validator to check data read from configuration files, I'm using System.ComponentModel.DataAnnotations
When I call
It always returns true. I've tried [StringLength(5)]
and [MaxLength(5)]
.


21.6k26 gold badges136 silver badges195 bronze badges
1 Answer
Try this:
Note: validateAllProperties = true
Documentation says:
true to validate all properties; if false, only required attributes are validated.
Brilliant design.
Luke PuplettLuke PuplettValidator.tryvalidateobject Always Returns True Story
21.6k26 gold badges136 silver badges195 bronze badges

Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.