Suggestion on ValidationResults

Topics: Validation Application Block
Mar 8, 2007 at 9:20 AM

I have just figured out that there is no way to separate two scenarios:

1. There are no validators at all assigned to the class properties and when I call Validation.Validate<>() I got IsValid true. That's ok.

2. I have one or more rule sets assigned to the class properties throuth configuration but the default rule set is not set up. Perhaps because of the manual configuration issue, somebody forgot something. I call Validate() and got IsValid true. There is no way to track configuration issues at run-time.

What if just add a property to the ValidationResults says that during validation several rule sets were found but VAB didn't understand which one it had to use (you asked for the default set but I didn't find it).

Mar 12, 2007 at 3:53 PM

I would put these suggestions in IssueTracker as they will get lost here is the forums.

I think your request is legitimate, but it may be a little late as I know all blocks except for PIAB are fairly set.

I know the Logging Application Block has similar functionality where when you log a message with a particular category that does not exist, you have the ability to send that output to a particular tracelistener.

You are asking for similar functionality such that if you don't specify a particular ruleset and a default ruleset is not specified, you would like to know about it via ValidationResults. Also, if you specify validation using a ruleset that does not exist, you would like to know about it, too.

Good idea.




David Hayden
Microsoft MVP C#
Oct 12, 2007 at 7:55 PM

This seems to be a pretty big problem to me. If someone mistypes the name of the ruleset, IsValid will always be true, with no warning at all, even if you have provided a default ruleset. Shouldn't the default behavior be more secure, not less? What is the best way to work around this bug? I would like to throw an exception if the validation uses a ruleset that does not exist.

Oct 13, 2007 at 6:08 AM
I understand your perspective, but this was a conscious decision. Calling Validate essentially means "run all of the defined validation rules, if any, and let me know if any of them report validation failures". There may be times when no validation rules are required, but the code doesn't know this and wants to make sure the data is valid.

That said, I agree this could cause some confusion if you incorrectly configure the block or mistype a rule name. Feel free to raise an issue and the team may choose to look at it in vNext.

Oct 13, 2007 at 9:31 PM
Thanks very much for your quick response.

I'm working on a way to work around this behavior but I'm not that experienced with the application blocks. I'm curious if you could suggest the best way to do the following without changing the VAB code:

1. Determine whether the specified ruleset exists.
2. Determine if any of the validators listed in the configuration file, for the specified ruleset, did not load correctly.

In vNext it would be nice to be able to configure the behavior when attempts to load a ruleset or validator fail. I’ll add a feature request to issue tracker when this thread concludes, so I can be as specific as possible about the behavior I’m looking for.