Validation Handler detailed exception message

Topics: Exception Handling Application Block, Logging Application Block, Policy Injection Application Block, Validation Application Block
Sep 3, 2007 at 1:27 PM
I'm using the Validation Handler to validate a call to a method. When one of the parameters is invalid it's throwing a "ArgumentValidationException". I'm catching this exception with the exception handling application block and log it to a file with a logging handler.

Is there a way to get to the individual messages of the validation rules of the rule set? I'm only getting a very generic "Parameter validation failed". I'd also like to log which parameter validation has failed.


Sep 3, 2007 at 3:15 PM

The name of the parameter that failed is available through the ParamName property, and you get the collection of validation results in the ValidationResults property. You will need to use an ExceptionFormatter that includes this information in the log entry, if the default ones don't do this already. By default all the public properties in the logged exception are retrieved using reflection, so my guess is that you're getting a rather uninformative "ValidationResults: ValidationResults" entry in your log.

Hope this helps,
Sep 4, 2007 at 12:19 PM
Indeed I was getting something like "ValidationResults: ValidationResults" in the log. I wrote my own ExceptionFormatter to fix this.

Thanks a lot Fernando!