Description
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()
Metadata
Metadata
Assignees
Labels
Type
Projects
Status