Tuesday, 23 August 2011

Exceptions inside IComparer.Compare(x, y)

When writing or using an implementation of IComparer.Compare(x,y) you encounter the following error message:

Unable to sort because the IComparer.Compare() method returns inconsistent results. Either a value does not compare equal to itself, or one value repeatedly compared to another value yields different results

It is highly likely that the code within the "Compare" statement is throwing an exception. We encountered this problem when trying to access an array out of bounds in a particular scenario. Updating our tests and our code to return a correct result in this scenario fixed the issue for us.

No comments:

Post a Comment