Compatability Issues with Enterprise Library Validation Application Block?

May 22, 2011 at 3:34 PM

Hi There,

Just wondering if anyone here is aware of any compatibility issues between MVC Foolproof Validation and the "Validation" class Validation Application Block of Enterprise Library 5.1.  I'm calling Validation.Validate(model) on a model class that contains a property decorated with a RequiredIfNotEmpty attribute, and the validation message I get back is "Validation using RequiredIfNotEmptyAttribute threw an exception: The method or operation is not implemented.".  I believe this error is thrown from within Enterprise Library.

// Returns a valResults collection containing the dodgy validation result for RequiredIfNotEmpty.
ValidationResults valResults = Validation.Validate(newAccount);
Enterprise Library 5.1 supports System.ComponentModel.DataAnnotations now, so I'm assuming it should also work with MVC Foolproof Validation also.

Lucas

May 23, 2011 at 6:02 AM
Edited May 23, 2011 at 6:25 AM

So it would seem this problem is caused by a NotImplementedException being thrown in the ModelAwareValidationAttribute.IsValid(object) method of Foolproof.  I'm going to investigate into implementing this method myself.  Is there any chance of having this method implemented in Foolproof in the future?

 

[AttributeUsage(AttributeTargets.Property)]
public abstract class ModelAwareValidationAttribute : ValidationAttribute
{        
        // ...
        public override bool IsValid(object value)
        {
            throw new NotImplementedException();
        }
        // ...
}

 

Lucas

 

UPDATE: eeep! I've since discovered why this method isn't implemented.  Most of the attributes in Foolproof need to be aware of the class that encapsulates the property the attribute decorates (duhh).  Looks like implementing this method isn't possible unless you can some how find out what the encapsulating class is from the property value that is passed through the IsValid method (I'm not sure if that's possible).