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

SignatureComparer::GetHashCode does not respect flags #427

Closed
Washi1337 opened this issue Apr 1, 2023 · 0 comments
Closed

SignatureComparer::GetHashCode does not respect flags #427

Washi1337 opened this issue Apr 1, 2023 · 0 comments
Labels
bug dotnet Issues related to AsmResolver.DotNet
Milestone

Comments

@Washi1337
Copy link
Owner

AsmResolver Version

5.2.0

.NET Version

.NET 6.0

Operating System

Windows

Describe the Bug

The SignatureComprer class can be configured to slightly relax the strict comparisons that are made for assemblies and types. This relaxation is however not reflected in the GetHashCode implementations. This can result in two members that would be considered equal according to the relaxed rules having two different hashcodes, making it unusable for HashSet<TMember> and Dictionary<TMember, TValue>.

How To Reproduce

var comparer = new SignatureComparer(SignatureComparisonFlags.VersionAgnostic);

var reference1 = KnownCorLibs.SystemRuntime_v5_0_0_0;
var reference2 = KnownCorLibs.SystemRuntime_v6_0_0_0;
Assert.Equal(reference1, reference2, comparer);
        
var set = new HashSet<AssemblyReference>(comparer);
Assert.True(set.Add(reference1));
Assert.False(set.Add(reference2));

Expected Behavior

All checks pass.

Actual Behavior

The last Assert.False fails.

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug dotnet Issues related to AsmResolver.DotNet
Projects
None yet
Development

No branches or pull requests

1 participant