Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Sep 1, 2025

Backport of #118291 to release/10.0, which resolved #118053.

Removes the IEquatable constraint from the ThrowIfEqual and ThrowIfNotEqual methods in ArgumentOutOfRangeException.

  • Allows these methods to be used with types that don't implement IEquatable, relying on EqualityComparer.Default.Equals for equality comparisons.
  • This broadens the applicability of these methods without sacrificing functionality.

/cc @jeffhandley @IDisposable

Customer Impact

  • Customer reported
  • Found internally
  • The IEquatable<T> constraint prevents customers from using the ThrowIfEqual and ThrowIfNotEqual methods on nullable value types (e.g., int?).
  • This change will also allow customers to use the ThrowIfEqual and ThrowIfNotEqual methods to validate enum arguments:

Regression

  • Yes
  • No

Testing

Existing product code and test code was already using this method. New tests are added in #119263 that explicitly exercise the customer scenarios mentioned above.

Risk

Low. The implementation is unchanged with the removal of the constraint. As @tannergooding mentioned on the issue discussion, "We use EqualityComparer in many similar cases and for similar reasons, it is correspondingly optimized as [Intrinsic] by the runtime in several scenarios."

@jeffhandley jeffhandley requested a review from artl93 September 2, 2025 11:45
@jeffhandley
Copy link
Member

@artl93 - For your consideration into .NET 10 RC2.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@artl93 artl93 left a comment

Choose a reason for hiding this comment

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

RC2 - removing constraint.

@artl93 artl93 merged commit 27371e4 into release/10.0 Sep 2, 2025
146 of 149 checks passed
@tannergooding tannergooding deleted the backport/pr-118291-to-release/10.0 branch September 2, 2025 21:26
@github-actions github-actions bot locked and limited conversation to collaborators Oct 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants