When "ToString" does not equal "ToString"

time to read 3 min | 554 words

The following code fail in a test!

I’ve zero idea why this happened, or how it can happen.

 

 

 

[Test]

public void ReallyStrangeBug()

{

      HybridDictionary dic = new HybridDictionary();

      foreach(MemberInfo member in typeof(object).GetMembers(BindingFlags.Public | BindingFlags.Instance))

            dic.Add(member.Name,member);

      Assert.In("ToString",dic.Keys);

}

 

 

The Assert.In is this method:

 

public class Assert

{

static public void In(Object test, IEnumerable enumerable)

{

    Assert.IsNotNull(enumerable,"Enumerable collection is a null reference");

    foreach(Object o in enumerable)

    {

      if (o==test)

            return;

    }

    Assert.Fail("{0} not found in collection",test);

} 

}

 

I debugged it to o==test, and I can see in watch that the values are the same, but it just doesn’t work!!!

 

The Assert.In belog to MbUnit framework, btw.

 

Any suggestions as to how it can happen are welcome.