Object Validator not working with FileConfiguration Source

Topics: Validation Application Block
May 14, 2007 at 7:35 PM
Edited May 14, 2007 at 7:35 PM
Has any one encountered problem with object validator when the validation rules are stored in a separate config file and loaded using the FileConfigurationSource?

In my case, I have stored all the validation rules in a Config file and I load it using the FileConfigurationSource as below:

IConfigurationSource validationRulesFile = new FileConfigurationSource("C:\TestUtility\Validation\TestObjectValidator.config");
Validator<Request> validator = ValidationFactory.CreateValidatorFromConfiguration<Request>("MEMBER_ENROLLMENT", validationRulesFile);

I have a object tree where I have a Class called "Request" that has a property called "Customer" which of the Type "Customer". I have an object validator for the Customer property. The issue is that the Object Validator doesn't fire when I load the validation rules from the separate configuration file. But when I specify the same validation rules in the App.Config file and create the validator as shown below, then the object validator works.
Validator<Request> validator = ValidationFactory.CreateValidator<Request>("MEMBER_ENROLLMENT");

It seems like a bug to me in the Validation Application block that object validator doesn't work when loaded using FileConfigurationSource.

Here are the validation rules.

<?xml version="1.0" encoding="utf-8"?>
<section name="validation" type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<type assemblyName="Test, Version=, Culture=neutral, PublicKeyToken=null"
<ruleset name="MEMBER_ENROLLMENT">
<property name="Customer">
<validator targetRuleset="MEMBER_ENROLLMENT" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.ObjectValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Object Validator" />
<type assemblyName="Test, Version=, Culture=neutral, PublicKeyToken=null"
<ruleset name="MEMBER_ENROLLMENT">
<property name="FirstName">
<validator negated="false" messageTemplate="First Name cannot be null"
messageTemplateResourceName="" messageTemplateResourceType=""
tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.NotNullValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Not Null Validator" />
May 15, 2007 at 9:18 AM
I have the same troubles when evaluating the Validation Block. I remeber that valitation from FileConfigurationSource did not work, so I but the rulesets in my app.config file or as attribute direct to the interface properties definitions.