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

ToFrozenDictionary function throws ArgumentOutOfRangeException exception in .Net 8 Pewview 7 #90567

Closed
CuteLeon opened this issue Aug 15, 2023 · 6 comments
Assignees
Labels
area-System.Collections bug in-pr There is an active PR which will close this issue when it is merged
Milestone

Comments

@CuteLeon
Copy link

Describe the bug

ToFrozenDictionary function throws ArgumentOutOfRangeException exception in .Net 8 Pewview 7

image

To Reproduce

var test = Enumerable.Empty<string>().ToFrozenDictionary(s => s);

Exceptions (if any)

System.ArgumentOutOfRangeException: 'minimumLength ('-2147483638') must be a non-negative value. (Parameter 'minimumLength')
Actual value was -2147483638.'

Further technical details

.NET SDK:
Version: 8.0.100-preview.7.23376.3
Commit: daebeea8ea

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Aug 15, 2023
@baronfel baronfel transferred this issue from dotnet/sdk Aug 15, 2023
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Aug 15, 2023
@vcsjones vcsjones 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 Aug 15, 2023
@ghost
Copy link

ghost commented Aug 15, 2023

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

Issue Details

Describe the bug

ToFrozenDictionary function throws ArgumentOutOfRangeException exception in .Net 8 Pewview 7

image

To Reproduce

var test = Enumerable.Empty<string>().ToFrozenDictionary(s => s);

Exceptions (if any)

System.ArgumentOutOfRangeException: 'minimumLength ('-2147483638') must be a non-negative value. (Parameter 'minimumLength')
Actual value was -2147483638.'

Further technical details

.NET SDK:
Version: 8.0.100-preview.7.23376.3
Commit: daebeea8ea

Author: CuteLeon
Assignees: -
Labels:

area-System.Collections, untriaged

Milestone: -

@eiriktsarpalis
Copy link
Member

Can reproduce, seems like this code

IEqualityComparer<string> stringComparer = (IEqualityComparer<string>)(object)comparer;
// keys and values are needed for every strategy
string[] keys = (string[])(object)source.Keys.ToArray();
TValue[] values = source.Values.ToArray();
// Calculate the minimum and maximum lengths of the strings in the dictionary. Several of the analyses need this.
int minLength = int.MaxValue, maxLength = 0;
foreach (string key in keys)
{
if (key.Length < minLength) minLength = key.Length;
if (key.Length > maxLength) maxLength = key.Length;
}
Debug.Assert(minLength >= 0 && maxLength >= minLength);
// Try to create an implementation that uses length buckets, where each bucket contains up to only a few strings of the same length.
FrozenDictionary<string, TValue>? frozenDictionary = LengthBucketsFrozenDictionary<TValue>.CreateLengthBucketsFrozenDictionaryIfAppropriate(keys, values, stringComparer, minLength, maxLength);

does not account for empty dictionary inputs. This appears to be causing this assertion

to fail in debug builds. cc @adamsitnik @stephentoub

@eiriktsarpalis eiriktsarpalis removed the untriaged New issue has not been triaged by the area owner label Aug 15, 2023
@eiriktsarpalis eiriktsarpalis added this to the 8.0.0 milestone Aug 15, 2023
@skyoxZ
Copy link
Contributor

skyoxZ commented Aug 15, 2023

@eiriktsarpalis It would fail eariier at Line 167: Debug.Assert(minLength >= 0 && maxLength >= minLength);

And another issue:


Maybe something is missing to ensure source is not empty at first?

@stephentoub stephentoub self-assigned this Aug 15, 2023
@ericstj ericstj added the in-pr There is an active PR which will close this issue when it is merged label Aug 15, 2023
@adamsitnik
Copy link
Member

Both the fix (#90595) and backport (#90599) got merged.

@CuteLeon
Copy link
Author

Will this change be deliveried in next release? I downgraded my Visual Studio and .Net 8 SDK to compile my solution.

@stephentoub
Copy link
Member

Yes, in .NET 8 RC1

@ghost ghost locked as resolved and limited conversation to collaborators Sep 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Collections bug in-pr There is an active PR which will close this issue when it is merged
Projects
None yet
Development

No branches or pull requests

7 participants