Skip to content

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

Closed
@AaronRobinsonMSFT

Description

@AaronRobinsonMSFT

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

Metadata

Metadata

Assignees

Labels

🏁 Release: .NET 9Work items for the .NET 9 release📌 seQUESTeredIdentifies that an issue has been imported into Quest.breaking-changeIndicates a .NET Core breaking changein-prThis issue will be closed (fixed) by an active pull request.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions