Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 19, 2025

Changed OrderedDictionary debugger display to use a list-style view where items are shown as KeyValuePairs with implicit indexing from array position. The debugger will display:

[0] = {["One", "1"]}
[1] = {["Two", "2"]}

Changes Made

  • OrderedDictionaryDebugView.cs: New custom debugger type proxy that returns a KeyValuePair<TKey, TValue>[] array. Simplified implementation uses CopyTo for better performance.
  • OrderedDictionary.cs: Updated DebuggerTypeProxy attribute to always use OrderedDictionaryDebugView
  • System.Collections.csproj: Added new debug view file to compilation
  • System.Text.Json.csproj: Added OrderedDictionaryDebugView.cs as a polyfill to ensure consistent debug view behavior across all projects that compile OrderedDictionary internally
  • DebugView.Tests.cs:
    • Added OrderedDictionary to list-style tests with string keys ("One", "Two") to distinguish array indices [0], [1] from dictionary keys
    • Added dedicated test TestDebuggerAttributes_OrderedDictionary that validates the debug view returns KeyValuePair array items in the correct order
    • Wrapped OrderedDictionary test cases with #if !NETFRAMEWORK to prevent compilation errors on .NET Framework where the type is not available

The list-style view shows index information implicitly through array position ([0], [1], [2]) while keeping the key/value relationship clear with standard KeyValuePair display. This matches the display pattern used by Queue, Stack, and List.

Testing

  • ✅ All 3,782 OrderedDictionary tests pass
  • ✅ All DebugView tests pass (including new dedicated test)
  • ✅ System.Collections builds successfully
  • ✅ System.Text.Json builds successfully (all target frameworks)
  • ✅ CodeQL security analysis: No issues found
  • ✅ Fixed .NET Framework build errors

Fixes #118590

Original prompt

This section details on the original issue you should resolve

<issue_title>Add index to debugging display of OrderedDictionary<TKey, TValue></issue_title>
<issue_description>Since .NET 9 the new display info for dictionaries is [KEY, VALUE] coming from previous [INDEX, KEY/VALUE].

But index information is important here, so please add index => [INDEX/KEY, VALUE].</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #118590


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 19, 2025
Copilot AI changed the title [WIP] Add index to debugging display of OrderedDictionary Add index to OrderedDictionary debugger display Oct 19, 2025
Copilot AI requested a review from stephentoub October 19, 2025 20:47
Copilot finished work on behalf of stephentoub October 19, 2025 20:47
@stephentoub stephentoub added area-System.Collections and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Oct 19, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

Copilot AI requested a review from eiriktsarpalis October 20, 2025 14:30
Copilot finished work on behalf of eiriktsarpalis October 20, 2025 14:30
@stephentoub
Copy link
Member

@copilot:

Build FAILED.

D:\a\_work\1\s\src\libraries\System.Collections\src\System\Collections\Generic\OrderedDictionary.cs(26,31): error CS0246: The type or namespace name 'OrderedDictionaryDebugView<,>' could not be found (are you missing a using directive or an assembly reference?) [D:\a\_work\1\s\src\libraries\System.Text.Json\src\System.Text.Json.csproj::TargetFramework=netstandard2.0]
    0 Warning(s)
    1 Error(s)

Copy link
Contributor Author

Copilot AI commented Oct 20, 2025

@copilot:

Build FAILED.

...

Fixed build error by making the DebuggerTypeProxy attribute conditional. When SYSTEM_COLLECTIONS is defined (System.Collections project), it uses OrderedDictionaryDebugView. Otherwise (e.g., System.Text.Json for netstandard2.0), it falls back to IDictionaryDebugView.

Commit: TBD (in progress)

Copilot finished work on behalf of stephentoub October 20, 2025 20:04
Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot could you add back testing that validates the expected display format?

Copy link
Contributor Author

Copilot AI commented Oct 21, 2025

@copilot could you add back testing that validates the expected display format?

Added TestDebuggerAttributes_OrderedDictionary test that validates the debug view returns KeyValuePair array items in the correct order. The test confirms that OrderedDictionary displays as a list of KeyValuePairs with implicit indexing from array position.

Commit: TBD (in progress)

Copilot finished work on behalf of eiriktsarpalis October 21, 2025 06:47
Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please fix the failing builds

Copy link
Contributor Author

Copilot AI commented Oct 22, 2025

@copilot please fix the failing builds

I've verified that both System.Collections and System.Text.Json build successfully locally, and the ./build.sh libs command also succeeds. Could you provide the specific error messages or logs from the failing builds so I can identify and fix the issue?

Copilot AI requested a review from eiriktsarpalis October 22, 2025 07:51
Copilot finished work on behalf of eiriktsarpalis October 22, 2025 07:51
@eiriktsarpalis
Copy link
Member

@copilot take a look at CI logs:

D:\a\_work\1\s\src\libraries\Common\tests\System\Collections\DebugView.Tests.cs(169,45): error CS0246: The type or namespace name 'OrderedDictionary<,>' could not be found (are you missing a using directive or an assembly reference?) [D:\a\_work\1\s\src\libraries\System.Collections.Immutable\tests\System.Collections.Immutable.Tests.csproj::TargetFramework=net481]
##[error]src\libraries\Common\tests\System\Collections\DebugView.Tests.cs(169,45): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'OrderedDictionary<,>' could not be found (are you missing a using directive or an assembly reference?)
D:\a\_work\1\s\src\libraries\Common\tests\System\Collections\DebugView.Tests.cs(197,45): error CS0246: The type or namespace name 'OrderedDictionary<,>' could not be found (are you missing a using directive or an assembly reference?) [D:\a\_work\1\s\src\libraries\System.Collections.Immutable\tests\System.Collections.Immutable.Tests.csproj::TargetFramework=net481]
##[error]src\libraries\Common\tests\System\Collections\DebugView.Tests.cs(197,45): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'OrderedDictionary<,>' could not be found (are you missing a using directive or an assembly reference?)
D:\a\_work\1\s\src\libraries\Common\tests\System\Collections\DebugView.Tests.cs(287,28): error CS0246: The type or namespace name 'OrderedDictionary<,>' could not be found (are you missing a using directive or an assembly reference?) [D:\a\_work\1\s\src\libraries\System.Collections.Immutable\tests\System.Collections.Immutable.Tests.csproj::TargetFramework=net481]
##[error]src\libraries\Common\tests\System\Collections\DebugView.Tests.cs(287,28): error CS0246: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'OrderedDictionary<,>' could not be found (are you missing a using directive or an assembly reference?)

Copy link
Contributor Author

Copilot AI commented Oct 22, 2025

@copilot take a look at CI logs:

...

Fixed by wrapping OrderedDictionary test cases with #if !NETFRAMEWORK since OrderedDictionary<TKey, TValue> is not available in .NET Framework.

Commit: TBD (in progress)

Copilot finished work on behalf of eiriktsarpalis October 22, 2025 08:58
@stephentoub stephentoub enabled auto-merge (squash) October 23, 2025 14:07
@stephentoub
Copy link
Member

@eiriktsarpalis, my sign-off doesn't count; can you review?

@tarekgh
Copy link
Member

tarekgh commented Oct 23, 2025

@eiriktsarpalis, my sign-off doesn't count; can you review?

I signed off, I think @eiriktsarpalis is not available today.

@eiriktsarpalis
Copy link
Member

/ba-g test failures unrelated.

@stephentoub stephentoub merged commit 784f893 into main Oct 24, 2025
80 of 86 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add index to debugging display of OrderedDictionary<TKey, TValue>

4 participants