-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[release/8.0] Fix nullable annotation for Validator.TryValidateValue and ValidateValue #91293
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @dotnet/area-system-componentmodel-dataannotations Issue DetailsBackport of #91286 to release/8.0 /cc @jeffhandley Customer Impact
Customers haven't historically called these methods directly, with it being more of a framework-level concern to orchestrate validation. With the Options Validation source generator introduced in .NET 8 though, we are now generating code into customers' projects that calls these methods directly so that Reflection can be bypassed at runtime. With the incorrect nullable annotation, we have to generate code that includes a TestingPending: #91286 (comment) Risk
|
...ies/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/Validator.cs
Show resolved
Hide resolved
@carlossanlop This one's ready for release/8.0 |
Backport of #91286 to release/8.0
/cc @jeffhandley
Customer Impact
System.ComponentModel.DataAnnotations.Validator
has methods for validating individual values against a list of validation attributes; they areValidateValue
andTryValidateValue
. Those two methods are annotated as not allowingnull
values to be validated, and the XML doc comments indicate the value cannot benull
as well. The annotation and comment were incorrect though, with the XML doc comment likely copied and pasted from the Object validation members long ago.Customers haven't historically called these methods directly, with it being more of a framework-level concern to orchestrate validation. With the Options Validation source generator introduced in .NET 8 though, we are now generating code into customers' projects that calls these methods directly so that Reflection can be bypassed at runtime. With the incorrect nullable annotation, we have to generate code that includes a
!
on the argument value. Taking this fix in .NET 8, the source generator can potentially stop emitting the!
into the generated code when targeting net8+. (That change is being considered but is not included in this PR).Testing
Compilation and unit tests succeed. A search across other dotnet org repos found no call sites to update.
Risk
Low. Only affects nullable annotation behavior at design-time, and this relaxes an erroneous annotation in a non-breaking way.