[Mono-list] Duplicate keys in hashtable when using Castle Monorail with Brail view engine

Robert Jordan robertj at gmx.net
Thu Apr 22 15:40:18 EDT 2010


On 22.04.2010 19:57, Simon Lindgren wrote:
> 	string path = "path";
> 	try {

This is a very interesting way of iterating over a dictionary ;)

> 		for (IDictionaryEnumerator n = parameters.GetEnumerator(); ;) {
> 			n.MoveNext();
> 			if (((string)n.Value) == "/Page1") {
> 				Console.WriteLine("path.GetHashCode(): {0}", path.GetHashCode());
> 				Console.WriteLine("Key.GetHashCode(): {0}", n.Key.GetHashCode());
> 				Console.WriteLine("Key.Equals(path): {0}", n.Key.Equals(path));
> 				Console.WriteLine("ReferenceEquals(Key, path): {0}", ReferenceEquals(n.Key, path));
> 				Console.WriteLine("Key == path: {0}", n.Key == path);

n.Key == path will always be false here, because String.Equals
will *not* be called.

You must cast n.Key to string:

	(string)n.Key == path

Check your code for similar errors and if you still think you've
found a bug, please file a case in Bugzilla with a self-contained
test case anyone can compile.

Robert



More information about the Mono-list mailing list