dotnet-api-docs icon indicating copy to clipboard operation
dotnet-api-docs copied to clipboard

Incorrect CustomValidationAttribute remarks

Open hrobertson opened this issue 6 years ago • 3 comments

Content: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.customvalidationattribute.method?view=netcore-2.2 Content source: xml/System.ComponentModel.DataAnnotations/CustomValidationAttribute.xml

The remarks for the Method property of CustomValidationAttribute incorrectly state that the specified method must return a Boolean and takes a ValidationResult out param. In .Net Core 2.2 at least, it must return a ValidationResult.

Maybe the signature is different in different languages?

Additionally, it would be preferable to have the valid signatures listed as code snippets rather than described in text.

hrobertson avatar Sep 05 '19 17:09 hrobertson

Thank you for your feedback @hrobertson.

@lajones, @divega, @ajcvickers can you help with this issue? Are there differences in behavior between .NET Framework and .NET Core for this API? Thanks.

mairaw avatar Sep 05 '19 20:09 mairaw

Doesn't look like it: https://referencesource.microsoft.com/#System.ComponentModel.DataAnnotations/DataAnnotations/CustomValidationAttribute.cs,db5138ec9e85f648

hrobertson avatar Sep 06 '19 12:09 hrobertson

Note that there are issues other than the wrong signature.

Copy-paste from #11769 that I opened and closed a bit too soon: The return value can also be a class derived of ValidationResult since .Net Core 3 or .Net 5 (this commit is dated to before .Net Core 3.0, but tagged with release/5.0).

It should also be noted that the ValidationContext instance passed on to the method is always null for .Net Framework because CustomValidationAttribute does not override ValidationAttribute.RequiresValidationContext (for .Net, this has been fixed by this commit in january 2016, so before the release of .Net Core 1.0).

Arkane5 avatar Oct 08 '25 08:10 Arkane5