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

KeyedCollection debug view doesn't work #96116

Closed
JamesNK opened this issue Dec 18, 2023 · 1 comment · Fixed by #96261
Closed

KeyedCollection debug view doesn't work #96116

JamesNK opened this issue Dec 18, 2023 · 1 comment · Fixed by #96261
Labels
area-System.Collections enhancement Product code improvement that does NOT require public API changes/additions help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@JamesNK
Copy link
Member

JamesNK commented Dec 18, 2023

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

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Dec 18, 2023
@ghost
Copy link

ghost commented Dec 18, 2023

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

Issue Details

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.

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.

Actual behavior

Default debug view.

Regression?

No response

Known Workarounds

No response

Configuration

net9.0

Other information

No response

Author: JamesNK
Assignees: -
Labels:

area-System.Collections, untriaged

Milestone: -

@eiriktsarpalis eiriktsarpalis added enhancement Product code improvement that does NOT require public API changes/additions and removed untriaged New issue has not been triaged by the area owner labels Dec 20, 2023
@eiriktsarpalis eiriktsarpalis added this to the Future milestone Dec 20, 2023
@eiriktsarpalis eiriktsarpalis added the help wanted [up-for-grabs] Good issue for external contributors label Dec 20, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Dec 21, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 12, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Feb 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Collections enhancement Product code improvement that does NOT require public API changes/additions help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants