Assert.AreEqual does not support IEquatable<T>

Bug #676560 reported by Lionel on 2010-11-17
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit Framework
Charlie Poole
NUnit V2
Fix Released
Simone Busoli

Bug Description

Assert.AreEqual does not support IEquatable<T>, ie Assert.AreEqual always returns false when comparing two objects for which IEquatable<T>.Equal would return true.

Related branches

Changed in nunitv2:
status: New → Confirmed
Charlie Poole (charlie.poole) wrote :

Implementing this requires some big changes in the way comparison is done, since we need to test for a generic interface. NUnitEqualityComparer is not generic in the current release and would have to be changed to be generic in order to implement this request. This is a good idea but there is a question of what release to do it in.

Changed in nunitv2:
status: Confirmed → Triaged
importance: Undecided → Medium
tags: added: feature framework
Changed in nunit-3.0:
status: New → Triaged
importance: Undecided → High
Changed in nunitv2:
milestone: none → 2.6.0
Charlie Poole (charlie.poole) wrote :

Although I initially scheduled this change to be implemented, I'm having doubts now. See the discussion at

Basically, I believe the change is only needed in cases where equality has not been correctly implemented, so we should not make it.

It would be helpful to discuss this on the list, where others can review it.

Changed in nunitv2:
assignee: nobody → Simone Busoli (simone.busoli)
Simone Busoli (simone.busoli) wrote :

I'm going to evaluate the feasibility of the change before deciding if this is something worth doing in the short time.

Simone Busoli (simone.busoli) wrote :

I have committed a first naive implementation on this branch:
My main concerns are related to performance as it requires reflection to work, but it's also true that it sits right before the last fallback which uses object.Equals and the equality has likely been handled before then.


Changed in nunitv2:
status: Triaged → In Progress
Lionel (ecrire-a-lionel) wrote :

Hi Charlie, hi Simone,

I mostly share the analysis made by Simone. I browsed yesterday .NET types implementing IEquatable<T> (which I forgot to do when I opened the ticket) and that's true that most but not all CLR types implementing IEquatable<T> also override Equals(object). Thinking about it, that's even a little weird that MS specs do not mention anything about the relationship between both... Anyway, if you can get Nunit to handle IEquatable<t>, that's be nice.

Thanks in advance,


Changed in nunitv2:
status: In Progress → Fix Committed
Changed in nunit-3.0:
milestone: none → 2.9.6
Changed in nunitv2:
status: Fix Committed → Fix Released
Changed in nunit-3.0:
assignee: nobody → Charlie Poole (charlie.poole)
Changed in nunit-3.0:
status: Triaged → Fix Committed
Changed in nunit-3.0:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers