Skip to content
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

[Breaking change]: Default Equals() and GetHashCode() throw for types marked with InlineArrayAttribute. #41498

Closed
1 of 3 tasks
AaronRobinsonMSFT opened this issue Jun 20, 2024 · 1 comment · Fixed by #41725
Assignees
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 9 Work items for the .NET 9 release in-pr This issue will be closed (fixed) by an active pull request. 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@AaronRobinsonMSFT
Copy link
Member

AaronRobinsonMSFT commented Jun 20, 2024

Description

The default behavior for Equals() and GetHashCode() on types marked with InlineArrayAttribute is now to throw a NotSupportedException. The user is required to override those methods if these functions are expected to not throw.``

Version

.NET 9 Preview 6

Previous behavior

The previous default implementation will only use the placeholder ref field when computing equality or the hash code.

New behavior

A NotSupportedException will always be thrown from the default implementations for Equals() and GetHashCode() when InlineArrayAttribute is applied to a type.

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
  • Behavioral change: Existing binaries may behave differently at run time.

Reason for change

The current behavior is not correct for either determining equality or hash code. Users are led into a false sense of correctness when calling these functions currently.

Recommended action

Users should implement both Equals() and GetHashCode() on all types marked with InlineArrayAttribute.

Feature area

Core .NET libraries

Affected APIs

System.ValueType.Equals(object) and System.ValueType.GetHashCode()


Associated WorkItem - 281894

@AaronRobinsonMSFT AaronRobinsonMSFT added doc-idea breaking-change Indicates a .NET Core breaking change labels Jun 20, 2024
@dotnet-bot dotnet-bot added ⌚ Not Triaged Not triaged labels Jun 20, 2024
@AaronRobinsonMSFT
Copy link
Member Author

Official API documentation is being updated with the new behavior - dotnet/dotnet-api-docs#10036

@gewarren gewarren removed the ⌚ Not Triaged Not triaged label Jun 20, 2024
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Jun 20, 2024
@gewarren gewarren removed the ⌚ Not Triaged Not triaged label Jul 9, 2024
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Jul 9, 2024
@gewarren gewarren removed the ⌚ Not Triaged Not triaged label Jul 9, 2024
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Jul 9, 2024
@gewarren gewarren removed the ⌚ Not Triaged Not triaged label Jul 9, 2024
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Jul 9, 2024
@gewarren gewarren added the 🏁 Release: .NET 9 Work items for the .NET 9 release label Jul 9, 2024
@gewarren gewarren added the 🗺️ reQUEST Triggers an issue to be imported into Quest. label Jul 9, 2024
@dotnet-bot dotnet-bot removed the ⌚ Not Triaged Not triaged label Jul 9, 2024
@sequestor sequestor bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels Jul 10, 2024
@gewarren gewarren moved this from 🔖 Ready to 👀 In review in dotnet/docs July 2024 Sprint Jul 10, 2024
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in dotnet/docs July 2024 Sprint Jul 10, 2024
@dotnet-policy-service dotnet-policy-service bot added the in-pr This issue will be closed (fixed) by an active pull request. label Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a .NET Core breaking change 🏁 Release: .NET 9 Work items for the .NET 9 release in-pr This issue will be closed (fixed) by an active pull request. 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants