-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Milestone
Description
It's defined like:
public static bool TryValidateValue(object value, ValidationContext validationContext, ICollection<ValidationResult>? validationResults, IEnumerable<ValidationAttribute> validationAttributes)and the XML doc comment states:
/// <param name="value">The value to test. It cannot be null.</param>However, the implementation appears to permit null (the only place it's used is being passed to an object? argument in a helper method), the purpose of an attribute like [Required] is to validate one isn't null (which suggests null could otherwise be valid, and the new .NET 8 source generator for options is having to emit code like:
if (!global::System.ComponentModel.DataAnnotations.Validator.TryValidateValue(options.Path!, context, validationResults, validationAttributes))
{
builder.AddResults(validationResults);
}(note the ! on the first argument) because the input might be null but the method is defined to not accept null.