Repository navigation
Keep a ConcurrentDictionary's type and comparer on the netstandard builds [patch] - #127
Merged
Merged
Conversation
…ilds [patch] CloneDictionary had a ConcurrentDictionary arm only under NET6_0_OR_GREATER, so on the netstandard2.0/2.1 builds (which .NET 5-7 apps, .NET Framework, Unity and Mono restore) a ConcurrentDictionary cloned through IDictionary or IReadOnlyDictionary came back as a plain Dictionary with the default comparer, and the typed overload dropped the comparer too. A reference-equality source with equal keys threw on clone. The arm now applies on every target. The comparer comes from ConcurrentDictionary.Comparer on .NET, and on netstandard from a cached run-time lookup of that property, falling back to the default comparer only on runtimes that do not have it. Correct the remarks and the CLAUDE.md target list. Fixes #125 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW3UyxP3KPcGGow8Vry
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5jpiuVuBRXSgitSY1
|
This was referenced Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



On the
netstandard2.0/netstandard2.1builds, which .NET 5–7 apps, .NET Framework, Unity and Mono restore,CloneDictionaryhad noConcurrentDictionaryarm, because the arm sat under#if NET6_0_OR_GREATER. AConcurrentDictionarycloned throughIDictionary/IReadOnlyDictionarytherefore came back as a plainDictionarywith the default comparer, and the typedDeepClone(this ConcurrentDictionary<,>)also dropped the comparer. A reference-equality source holding equal keys threwArgumentExceptionon clone.Changes
ConcurrentDictionaryarm now applies on every target.ConcurrentComparer<TKey, TValue>helper supplies the comparer to bothCloneDictionaryand the typed overload:ConcurrentDictionary.Comparerdirectly.WrappedDictionarydoes, so a .NET 6+ runtime keeps the comparer. Only runtimes without the property fall back toEqualityComparer<TKey>.Default.Verification
The test project targets only
net10.0and binds to the net10 build, so it never runs the netstandard code. Pointing it at a netstandard build doesn't compile today: the immutable-collection tests hit overload ambiguity, and netstandard2.0 lacks nullability attributes, which triggers CA1062. Instead I checked with a scratch console harness that references the library withSetTargetFramework=netstandard2.0/netstandard2.1. I confirmed the loaded assembly'sTargetFrameworkattribute in each case.The harness ran the three tests the issue names,
ConcurrentDictionary_ThroughIDictionary_KeepsComparer,ConcurrentDictionary_WithReferenceEquality_ClonesEqualKeysandConcurrentDictionary_DeepClone_ShouldKeepComparer, plus theIReadOnlyDictionarypath and the typed reference-equality case.ArgumentException)The full
DeepClone.Testsuite passes on net10.0: 99/99.Not included: a CI leg that runs the tests against the netstandard builds, which the triage suggests. It first needs the test project to compile against netstandard (the immutable-overload and CA1062 issues above), so it is worth its own issue.
Fixes #125
Generated by Claude Code