Skip to content

Fix StackOverflow on circular object graphs by restoring ReferenceComparer#8

Closed
jeme with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-stack-overflow-in-constraint
Closed

Fix StackOverflow on circular object graphs by restoring ReferenceComparer#8
jeme with Copilot wants to merge 3 commits into
masterfrom
copilot/fix-stack-overflow-in-constraint

Conversation

Copilot AI commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

When traversing object graphs with circular references, the HashSet<object> used to track visited nodes was inadvertently relying on object.Equals(). For types that override Equals() with property-walking logic, this re-enters the constraint traversal, causing a StackOverflow.

Changes

  • ObjectPropertiesEqualsConstraint.cs: Restore new ReferenceComparer() as the HashSet comparer — uses ReferenceEquals (pointer comparison) instead of object.Equals(), guaranteeing cycle detection without recursion.
// Before (broken — triggers Equals() which can recurse)
private readonly HashSet<object> references = new HashSet<object>(/*new ReferenceComparer()*/);

// After (correct — pure pointer comparison, no recursion)
private readonly HashSet<object> references = new HashSet<object>(new ReferenceComparer());

Copilot AI assigned Copilot and jeme Jun 1, 2026
Copilot AI changed the title Fix stack overflow in InitializeProperties under .NET 9 Fix StackOverflowException in InitializeProperties under .NET 9 Jun 1, 2026
Copilot finished work on behalf of jeme June 1, 2026 08:52
Copilot AI requested a review from jeme June 1, 2026 08:52
Copilot AI changed the title Fix StackOverflowException in InitializeProperties under .NET 9 Fix StackOverflow on circular object graphs by restoring ReferenceComparer Jun 1, 2026
Copilot finished work on behalf of jeme June 1, 2026 12:22
Copilot finished work on behalf of jeme June 1, 2026 12:32
@jeme jeme closed this Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants