Skip to content

Clarify ObjectInstance behavior when no owning object is available - #131900

Merged
ViveliDuCh merged 4 commits into
dotnet:mainfrom
ViveliDuCh:dev/vivianad/objectinstance-remarks-update
Aug 7, 2026
Merged

Clarify ObjectInstance behavior when no owning object is available#131900
ViveliDuCh merged 4 commits into
dotnet:mainfrom
ViveliDuCh:dev/vivianad/objectinstance-remarks-update

Conversation

@ViveliDuCh

Copy link
Copy Markdown
Member

Updated the doc comment to make it clear that ObjectInstance has no meaningful value when validation is performed outside the context of an owning object, helping avoid incorrect assumptions by attribute authors.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the XML doc remarks for ValidationContext.ObjectInstance to clarify expectations about the object instance available during validation, especially in scenarios where an “owning” object may not exist.

Changes:

  • Adds a new remark explaining ObjectInstance is not meaningful in some ownerless/standalone validation scenarios.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 5, 2026 20:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/ValidationContext.cs:152

  • The new remarks call out that ObjectInstance "may be a placeholder", but ObjectInstance is always whatever was supplied to the ValidationContext constructor. Saying it's a placeholder can read like framework-provided behavior (or that it has no value at all), and it also conflicts a bit with the summary stating this is the object instance being validated. Consider wording this in terms of the constructor-provided instance not necessarily being an owning object when validating standalone values.
        ///     When validation is performed without an owning object (for example, validating standalone values),
        ///     <see cref="ObjectInstance" /> may be a placeholder and should not be treated as the owner of the value.

Co-authored-by: Jeff Handley <jeffhandley@users.noreply.github.com>
Copilot AI review requested due to automatic review settings August 5, 2026 21:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/ValidationContext.cs:156

  • The new remarks say ObjectInstance "may be a placeholder" for standalone validation, but the placeholder comes from whatever the caller passes into ValidationContext (the framework doesn’t supply one). Calling this out explicitly (and pointing to Validator.TryValidateValue) would make the guidance more accurate/actionable for attribute authors.
        ///     <para>
        ///     When validation is performed without an owning object (for example, validating standalone values),
        ///     <see cref="ObjectInstance" /> may be a placeholder and should not be treated as the owner of the value.
        ///     </para>

Copilot AI review requested due to automatic review settings August 6, 2026 22:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

@ViveliDuCh

Copy link
Copy Markdown
Member Author

/ba-g Helix timeout (7 jobs show as unfinished or unprocessed) and known flake #125825 only

@ViveliDuCh
ViveliDuCh merged commit 26b8250 into dotnet:main Aug 7, 2026
82 of 84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants