Validation Context is null in custom attribute

Mar 4, 2015 at 11:47 AM

When we create custom attribute,and we want validation context also,then in custom class isValid method ,validation context object is always null.

I think this happen because of Validate method in DataAnnotationsObjectValidator.cs file
this line

so from here when it go to custom class isValid,it is not able to pass validation context object.

When IsValid is overloaded with IsValid(property.GetValue(input),new ValidationContext(input,null,null)
then it gives error.

I am not getting any nicer solution .
I think we can solve this by declaring
one public static object and store the input in this object.
public static object objCurrentValidationObject = null;
This way in custom class isValid method,we can get the Current object which is being validated.

Hope I am clear .
Please correct me where I am wrong.