Problem with ValidationProvider - VAB

Topics: Validation Application Block
Apr 7, 2010 at 8:54 AM


I use with ValidationProvider & ErrorProvider to integrate VAB with winforms.

The validation was done on dateTimePicker with properties with PropertyComparisonValidator attribute.

The ErrorProvider (Icon in lose focus) works well.

In "Save" button I want to go through all the controls and call PerformValidation(control)

In the DateTimePicker control - I got Exception: "Object reference not set to an instance of an object."

The Exception happened in method:

public ValidatedControlItem GetExistingValidatedControlItem(string sourcePropertyName);

Someone Know why???



Apr 7, 2010 at 10:23 AM

Hi sarae,

Could you post the full exception encountered here? Also, can you verify if the PropertyToCompare of your PropertyComparisonValidator exist? And lastly, can you check if the ValidatedProperty in your DateTimePicker control is set correctly?

If the problem still persists, to help reproduce your problem can you also post your code here? Thanks.


Apr 7, 2010 at 10:48 AM


First, thanks for your response!

My validation code is:

public class SearchParameters



                [PropertyComparisonValidator("SentDateTill", ComparisonOperator.LessThanEqual, MessageTemplateResourceName = "ErrSentDate", MessageTemplateResourceType = typeof(ValidationResources.ErrorMessages))]

        public DateTime SentDateFrom { get; set; }


        public DateTime SentDateTill { get; set; }



In DateTimePicker ValidatedProperty is Value.

Thestrange is that the Error provider works well!

Many Thanks!


Apr 7, 2010 at 10:54 AM


Sorry, I forgot the full excetion.


at Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WinForms.ValidationProvider.GetExistingValidatedControlItem(String sourcePropertyName)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WinForms.PropertyMappedControlValueAccess.GetValue(Object source, Object& value, String& valueAccessFailureMessage)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Validators.ValueAccessComparisonValidator.DoValidate(Object objectToValidate, Object currentTarget, String key, ValidationResults validationResults)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Validators.ValueAccessValidator.DoValidate(Object objectToValidate, Object currentTarget, String key, ValidationResults validationResults)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Validator.Validate(Object target)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WinForms.ValidationProvider.PerformValidation(ValidatedControlItem validatedControlItem)
   at Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WinForms.ValidationProvider.PerformValidation(Control control)


Apr 7, 2010 at 11:24 AM

Sorry I meant the SourcePropertyName of your DateTimePicker.

Anyway, I think its pretty hard to guess what could possibly be wrong in your application from here.

With this, can you send me a copy of your App so that I can take a look? My email is  . Thanks