IDataErrorInfo and validation block

Topics: Validation Application Block
Apr 26, 2009 at 8:27 PM
Hi all,

I encouter a problem with implementing the IDataErrorInfo using the validation block.
1. I declared a base class that implements IDataErrorInfo interfase.
2. In the indexer method I call a method on interface witch makes the validation.

Here is the Base calss :


public class BusinessObjectsBaseClass IDataErrorInfo{
public IValidator Validator { get; set; }



IDataErrorInfo Members
public string Error
get { return string.Empty; }



public string this[string columnName]
get { return ValidateOverride(columnName, this); }



protected virtual string ValidateOverride(string propertyName, object instance)
return Validator.Validate(propertyName, instance);


I have also a class witch implements the IValidator and uses the validation block as follows:



class EnterpriseLibraryValidator : IValidator{




IValidator Members
public string Validate(string propertyName, object instance)
ValidationResults results = Microsoft.Practices.EnterpriseLibrary.Validation.Validation.Validate(instance);
var validationResult = results.Where(v => v.Key == propertyName);
if (validationResult.Count() != 0)
return validationResult.First().Message;
return string.Empty;


When I pass any instanse of my business object witch have validation attributes , the validation doesn't work. If I define strongle the type in the Validate method then It works, like
ValidationResults results = Microsoft.Practices.EnterpriseLibrary.Validation.Validation.Validate<MyObject>(instance as MyObject);

Alsoi tried to use generic type and the same problem.

Any suggestions.


Apr 27, 2009 at 9:03 AM

I think it wont work because the Validation Application Block will try to create a validator for the type object and not the specific type that you expect. Replace the 

ValidationResults results = Microsoft.Practices.EnterpriseLibrary.Validation.Validation.Validate(instance);



Validator validator = ValidationFactory.CreateValidator(instance.GetType());
ValidationResults results = validator.Validate(instance);

This works fine for me, please see if this also works for you.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.


Apr 27, 2009 at 11:34 AM
Thanks you very much. It works !!!