Validate method returns always Valid No matter what.

Topics: Validation Application Block
Jun 17, 2010 at 1:05 PM
Edited Jun 17, 2010 at 1:08 PM

Hey all,

I spent the all day trying to have a single property validated... I could not manage :(

The validation blocks looks good on paper but it is sade it is that difficule to setup.

 By the way I spent already half a day trying to have a MetaData class in combinaison with Data annotation.It seems it does not work with WPF. Great!!!! could have been stated in the documentation.

If any of you have an idea on my problem here is the code:

//Creation of the validator

var configuration = new FileConfigurationSource(@"ValidationConfiguration.config");

//the file is found. I tried with a tipo on the file name and it crashs

//Check -> configuration is not null

//Initialize the factory

var factory = new ConfigurationValidatorFactory(configuration,new ValidationInstrumentationProvider(false,false,"Kpm Finance Client"));

// the factory is !=null. Question Why having the validation instrumentaiton mandatory???? Just to mkae it more complex? :)

_validator = factory.CreateValidator<Office>();

//_validator !=null -> It is intialized.

var office = new Office {Name="123456789123456789123456789"}

var results = Validator.Validate(office);

//results.Count always equals to 0

the config file contains 

<configuration>
    <configSections>
        <section name="validation" type="Microsoft.Practices.EnterpriseLibrary.Validation.Configuration.ValidationSettings, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    </configSections>
    <validation>
        <type name="Kpm.Finance.Server.Domain.Office" defaultRuleset="DefaultRuleSet"
            assemblyName="Kpm.Finance.Server.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
            <ruleset name="DefaultRuleSet">
                <properties>
                    <property name="Name">
                        <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                            upperBound="20" lowerBoundType="Exclusive" messageTemplate="Le nom du bureau doit être compris entre 1 et 100 caractères."
                            name="String Lenght Validator" />
                        <validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.ContainsCharactersValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                            characterSet="XXX" containsCharacter="Any" name="Contains Characters Validator" />
                    </property>
                </properties>
            </ruleset>
        </type>
    </validation>
</configuration>

<font face="Consolas" size="2" color="#0000ff">

 

</font>

 

 

 any help will be appreciated before I totaly give up on the validation block :)

Jun 18, 2010 at 1:55 AM

You can create a ConfigurationValidationFactory without having to specify an instrumentation provider by using this code:

ConfigurationValidatorFactory factory = ConfigurationValidatorFactory.FromConfigurationSource(configSource);

I don't see anything wrong with your config though.   Could you send a sample project which repro this?

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com