Question

Enterprise Library 5 reads from my app.config and validates perfectly.

With the following references:

Microsoft.Practices.EnterpriseLibrary.Common v 5.0.414.0 Microsoft.Practices.EnterpriseLibrary.Validation v 5.0.414.0

and the following configuration (in app.config):

<configSections>
<section name="validation"
         type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings,
             Microsoft.Practices.EnterpriseLibrary.Validation" />
</configSections>

<validation>
<type name="WindowsFormsApplication1.AThing" assemblyName="WindowsFormsApplication1" defaultRuleset="default">
  <ruleset name="default">
    <properties>
      <property name="Name">            
        <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.NotNullValidator, Microsoft.Practices.EnterpriseLibrary.Validation"
          negated="false" messageTemplate="Customer must have valid no"
          tag="CustomerNo" name="Not Null Validator" />
      </property>
    </properties>
  </ruleset>
</type>
</validation>

and the following code:

public class AThing
{
    public string Name { get; set; }
}

...
AThing bob = new AThing();
bob.Name = null;
ValidationResults vr = Validation.Validate(bob, "default");
Debug.Assert(!vr.IsValid); 
...

vr.IsValid is, correctly, false (because "Name" is null, and I have a NotNull Validator).

However, when I replace the references to the following:

Microsoft.Practices.EnterpriseLibrary.Common v 6.0.0.0 Microsoft.Practices.EnterpriseLibrary.Validation v 6.0.0.0

and change nothing else, vs.IsValid is true...

After much googling and stack overflowing, I only found this Enterprise Library 6 validation config file, (another user with a similar issue...) (*this on CodePlex)

Was it helpful?

Solution

Enterprise Library 6 does not automatically bootstrap the XML configuration. This is different than previous versions. So now you have to bootstrap the blocks at startup (usually).

So for validation it would look something like this:

// Bootstrap the block at startup using default configuration file
ValidationFactory.SetDefaultConfigurationValidatorFactory(
    new SystemConfigurationSource());

AThing bob = new AThing();
bob.Name = null;

ValidationResults vr = Validation.Validate(bob, "default");
Debug.Assert(!vr.IsValid); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top