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

Fix equality comparer used in ReferencedObjectCollection's overflow dictionary #7433

Conversation

ReubenBond
Copy link
Member

@ReubenBond ReubenBond commented Dec 9, 2021

ReferencedObjectCollection uses a hybrid approach to storing object references: an array is used for tracking the first 64 reference objects and a Dictionary<object, uint> is used for subsequent objects.

That dictionary uses ReferenceEqualsComparer.Default to check for equality. ReferenceEqualsComparer doesn't explicitly define a Default property, though, instead it inherits from EqualityComparer<object>. This was the mistake: the Default property was returning the default equality comparer which means we do not have reference equality. Eg, It can tell you that a Uri and string are equal, as it was in the test case which @mcm2020 provided.

Microsoft Reviewers: Open in CodeFlow

@ReubenBond ReubenBond force-pushed the fix/referencedobjectcollection-overflow-dictionary branch from cb7d214 to 6cfc114 Compare December 10, 2021 03:31
@benjaminpetit benjaminpetit merged commit 328aa07 into dotnet:main Dec 10, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants