[Breaking change]: Default Equals()
and GetHashCode()
throw for types marked with InlineArrayAttribute
.
#41498
Closed
1 of 3 tasks
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.
Description
The default behavior for
Equals()
andGetHashCode()
on types marked withInlineArrayAttribute
is now to throw aNotSupportedException
. 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 forEquals()
andGetHashCode()
whenInlineArrayAttribute
is applied to a type.Type of breaking change
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()
andGetHashCode()
on all types marked withInlineArrayAttribute
.Feature area
Core .NET libraries
Affected APIs
System.ValueType.Equals(object)
andSystem.ValueType.GetHashCode()
Associated WorkItem - 281894
The text was updated successfully, but these errors were encountered: