I am using the Ent Lib 3.0 configuration console to configure VAB in my class library. I am applying the standard Range Validator onto an Integer property.
I pointed the console to open my executable's App.Config to configure it and I am configuring this integer to have a range between 8 and 40 both using InInclusive bound type.
When I asked the console to validate it (Ctrl-Shift-V), it complains of an error:
"The value for UpperBound should be greater than the value for LowerBound."
That's odd! To me 40 > 8.
A bit of experiment suggests to me that the console simply using String.Compare(upperBound, lowerBound) > 0. In this case, String.Compare( "40", "8" ) < 0 but String.Compare( "40", "3" ) > 0.
So the console does not appear to inspect the property for the data type, convert the lower and upper string values to that type and then check the specification to determine is it valid.
Just to demonstrate that the validator works in runtime, I enter some rubbish to allow the configuration console to save the specification to the App.Config build the program can then use the Validation.ValidateFromConfiguration<>() to validate.
Prior to running the program, I modify the config file to contain the range 8 to 40 as follows:
<type assemblyName="DemoClassLib, Version=184.108.40.206, Culture=neutral, PublicKeyToken=null" name="DemoClassLib.Person">
<validator lowerBound="8" lowerBoundType="Inclusive" upperBound="40" upperBoundType="Inclusive" negated="false" messageTemplate="Not acceptable age" messageTemplateResourceName="" messageTemplateResourceType="" tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RangeValidator,
Microsoft.Practices.EnterpriseLibrary.Validation, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" name="Range Validator" />
It runs properly and validating according to the rule prescribed above.
I ended up enter 08 for lower bound and 40 for upper bound to get over the validation failure preventing me to save the config file.
Or could this be a bug?
Same issue in Ent Lib 3.1.
Looks like a bug to me.
The Visual Studio Integrated Configuration Editor works fine in this scenario, however.
I would use the Visual Studio Editor.
Created a WorkItem:
Microsoft MVP C#
Similarly using the range validator,
with ranges of '0 to 180', then, would values like '34' be invalid, and a value like '1000' be valid?
The original post described a design time issue, but you seem to be asking about runtime behavior. Can you please clarify your question?