views:

198

answers:

3

This is the property declaration in question:

 [RangeValidator(1,RangeBoundaryType.Inclusive,255,RangeBoundaryType.Inclusive,MessageTemplate = "StartFlexibility is out of range")]
    public byte StartFlexibility { get; set; }

When the validate method is called, a FormatException is thrown telling me that the value type needs to be Int32.

How to fix, please?

A: 

I've never used the RangeValidator class/attribute, but is it an issue that you have 256 as an upper bound when a byte can only get to 255?

Chris Shaffer
+1  A: 

well... the quick obvious fix will be change the type to short or int,

but another observation i want to do, is with the range. You are telling the RangeValidator to take a inclusive range between 1 and 256, but you just can assign a byte value till 255, maybe that's the compiler reason to cry out.

The RangeValidator is also infering the type of the Range from the parameters, so, try casting

[RangeValidator((byte) 1, ...
Jhonny D. Cano -Leftware-
A: 

as Jhonny says, cast to byte...but more like this

[RangeValidator(typeof(Byte), "1", RangeBoundaryType.Inclusive, "255", RangeBoundaryType.Inclusive, MessageTemplate = "Some message")]

the other option would be to call the range validator in a SelfValidation message and cast there

Justin S.