Custom Validator missing constructor

Topics: Validation Application Block
Oct 12, 2007 at 4:31 AM
I've got an issue with creating a Custom Validator in that the one I've created and even the ones in the samples work when using it as an attribute, but I get a "Missing Constructor" exception when using the same custom validator via a config file. Any thoughts from someone who has solved this would be good.
Oct 12, 2007 at 6:02 AM
Make sure you have the [ConfigurationElementType(typeof(CustomValidatorData))] and a constructor that takes a single NameValueCollection parameter, like the samples in the QuickStart:
    [ConfigurationElementType(typeof(CustomValidatorData))]
    public class DivisibleByValidator : Validator<int>
    {
        private int divisor;
 
        public DivisibleByValidator(NameValueCollection attributes) : base(null, null)
        {
            divisor = Int32.Parse(attributes.Get("Divisor"));
        }
        //...
    }

Tom
Oct 12, 2007 at 6:08 AM
Thanks Tom

Got it working - the (NameValueCollection attributes) is required regardless of whether you use attributes or not. Got this info off one of the other message posts here. Good forum :-)