Comparer, created by HashSet<>::CreateSetComparer() is not correct. - by Viacheslav Ivanov

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 691427 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 9/28/2011 10:26:00 AM
Access Restriction Public


Comparer, created by HashSet<>::CreateSetComparer() works incorrectly in case, when set uses a custom comparer.
Sign in to post a comment.
Posted by Viacheslav Ivanov on 5/19/2012 at 3:31 PM
Hi, Immo!

I can not use you workaround, because I need a HashSet<> of HashSets<> or Dictionary<HashSet<>,> and I do not need an Equals implementation. I need a correct IEqualityComparer<HashSet<>>, that returns the same hash codes for two equal sets.
Posted by Microsoft on 10/7/2011 at 4:40 PM
Hi Viacheslav,

Thank you very much for your feedback. We confirm that this is an issue with the existing APIs. As I a workaround we would recommend that you implement you own method to compare the two sets:

public static bool CompareTwoSets<T>(ISet<T> first, ISet<T> second, IEqualityComparer<T> comparer)
     if(first == null && second == null)
         return true;

     if(first == null || second == null)
         return false;

     if(first.Count != second.Count)
         return false;

     HashSet<T> s = new HashSet<T>(first, comparer);

     foreach(T item in second)
             return false;

     return true;

Unfortunately, we cannot fix the existing APIs as this change can break code that already took a dependency on today's behavior. We will consider adding an overload in the future that has different semantics.

Immo Landwerth
Program Manager
.NET Base Class Libraries Team
Posted by MS-Moderator07 [Feedback Moderator] on 9/28/2011 at 7:33 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by MS-Moderator01 on 9/28/2011 at 10:43 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(