28.08.2019»»среда

Validator.tryvalidateobject Always Returns True

28.08.2019
    72 - Comments
  1. Validator.tryvalidateobject Always Returns True Story
  2. 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)].

Luke PuplettValidator.tryvalidateobjectAlwaysLuke Puplett
21.6k26 gold badges136 silver badges195 bronze badges

1 Answer

Try this:

Note: validateAllProperties = true

Documentation says:

Guru charitra in english pdf

true to validate all properties; if false, only required attributes are validated.

Brilliant design.

Luke PuplettLuke Puplett

Validator.tryvalidateobject Always Returns True Story

21.6k26 gold badges136 silver badges195 bronze badges
Returns
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Validator.tryvalidateobject Always Returns True Value

Not the answer you're looking for? Browse other questions tagged c# or ask your own question.