Skip to content

KeyedCollection debug view doesn't work #96116

@JamesNK

Description

@JamesNK

Description

KeyedCollection abstract base class has a debug proxy defined:

[Serializable]
[DebuggerTypeProxy(typeof(CollectionDebugView<>))]
[DebuggerDisplay("Count = {Count}")]
[System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
public abstract class KeyedCollection<TKey, TItem> : Collection<TItem> where TKey : notnull

However, I don't believe it works correctly because it assumes one open generic type and KeyedCollection has two.

And no debug proxy is used when viewing a type that inherits from KeyedCollection with the debugger:
image

Reproduction Steps

var c = new MyKeyedCollection();
c.Add(new KeyValuePair<string, string>("Name", "Value"));

internal class MyKeyedCollection : KeyedCollection<string, KeyValuePair<string, string>>
{
    protected override string GetKeyForItem(KeyValuePair<string, string> item)
    {
        return item.Key;
    }
}

Expected behavior

A user-friendly debug view.

Should the debug view be a list or a name/value collection? A list is probably more appropriate.

Actual behavior

Default debug view.

Regression?

No response

Known Workarounds

No response

Configuration

net9.0

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.CollectionsenhancementProduct code improvement that does NOT require public API changes/additionshelp wanted[up-for-grabs] Good issue for external contributors

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions