Conversation
…-same-value behavior Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix ImmutableDictionary.Add ArgumentException documentation
Fix ImmutableDictionary ArgumentException docs: clarify duplicate-key-same-value is a no-op
Mar 19, 2026
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-collections |
gewarren
approved these changes
Mar 19, 2026
eiriktsarpalis
approved these changes
Mar 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the API reference XML docs for System.Collections.Immutable.ImmutableDictionary to accurately describe when an ArgumentException is thrown on duplicate keys, aligning the documentation with the implemented “throw only if the existing value differs” behavior.
Changes:
- Updated
ArgumentExceptiontext forIDictionary<TKey,TValue>.Add(explicit impl) andImmutableDictionary<TKey,TValue>.Builder.Addto clarify it throws only when the existing value is different. - Added missing
ArgumentExceptiondocumentation to the enumerable-sourceToImmutableDictionaryoverloads to match the same “different value” collision behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| xml/System.Collections.Immutable/ImmutableDictionary`2+Builder.xml | Clarifies duplicate-key exception wording for Builder.Add. |
| xml/System.Collections.Immutable/ImmutableDictionary`2.xml | Clarifies duplicate-key exception wording for the explicit IDictionary<TKey,TValue>.Add implementation. |
| xml/System.Collections.Immutable/ImmutableDictionary.xml | Adds consistent ArgumentException docs to enumerable-source ToImmutableDictionary overloads. |
You can also share your feedback on Copilot code review. Take the survey.
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.
ImmutableDictionaryusesKeyCollisionBehavior.ThrowIfValueDifferent, meaning adding a duplicate key with an equal value is silently ignored — but the existingArgumentExceptiondocs implied an exception is thrown for any duplicate key.Changes
ImmutableDictionary2.xml** — FixedIDictionary<TKey,TValue>.Addexplicit interface impl:"same key already exists"→"same key but a different value already exists"`ImmutableDictionary2+Builder.xml** — Same fix forBuilder.Add`ImmutableDictionary.xml— Added missingArgumentExceptiondocs to all 8ToImmutableDictionaryenumerable-source overloads (key/value selector variants included); theBuilder-based overload is excluded since a builder can't hold duplicate keysThe public
ImmutableDictionary<TKey,TValue>.Addalready had the correct wording ("but has a different value") and was left unchanged.Original prompt
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.