Skip to content

Incorrect information about method parameter(s) and return value #11769

@Arkane5

Description

@Arkane5

Type of issue

Other (describe below)

Description

"it must return a Boolean value": this sentence (and others) is wrong, for .Net Framework (4.8.1 and maybe older versions) and all versions of .Net.

Actual:
This documentation says: method prototype should look like bool MyMethod(<type> value) or bool MyMethod(<type> value, ValidationContext context, out ValidationResult result).

Expected:
Documentation says that method prototype should look like ValidationResult? MyMethod(<type> value) or ValidationResult? MyMethod(<type> value, ValidationContext? context).
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).

The correct documentation can be found in the source code of CustomValidationAttribute: .Net/.Net Framework.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.customvalidationattribute.method

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.ComponentModel.DataAnnotations/CustomValidationAttribute.xml

Document Version Independent Id

ba1cc98b-e6b7-bf0a-9307-d450b7ff2a35

Platform Id

3ece839c-4d1d-102f-b15f-c7f88d39bc62

Article author

@dotnet-bot

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions