[Mono-list] Duplicate keys in hashtable when using Castle Monorail with Brail view engine
Simon Lindgren
simon.n.lindgren at gmail.com
Thu Apr 22 13:57:32 EDT 2010
Hello list,
I can not figure this one out. I have an ASP.NET project in which I use
Castle Monorail together with the Brail view engine. For the project I
have written a custom routing rule, which is supposed to receive a
Hashtable (well, IDictionary actually, but it is a Hashtable) containing
the parameters with which to generate a URL.
The key I'm looking for is in the Hashtable, but it is not possible to
access it. The lookup simply fails. I've looked at the table both in the
soft debugger and by looping through it using an iterator. I can insert
a new element with the same key as the one I want to access. This new
element does not take the place of my wanted row, so now there is a
duplicate key in the table. If I try to insert one more entry with that
same key I get an ArgumentException about duplicate keys. I've also
ruled out special characters as a cause by manually finding the correct
entry and comparing the actual key to my input key.
I'm really at a loss here, a part of the code is below:
public string CreateUrl(IDictionary parameters)
{
//Log the contents of the parameter dictionary
StringBuilder s = new StringBuilder();
s.Append("{");
foreach (DictionaryEntry entry in parameters) {
s.Append(String.Format("{0} {1} = {2}, ", entry.Key.GetType().ToString(), (string)entry.Key, (entry.Value ?? "null")));
}
s.Remove(s.Length - 2, 2);
s.Append('}');
Console.WriteLine("Parameters: " + s.ToString());
string path = "path";
try {
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);
}
}
}
catch (InvalidOperationException endOfDictionary) {} //just swallow
Console.WriteLine("parameters.Contains(path): {0}", parameters.Contains(path));
parameters.Add(path, "/Page");
Console.WriteLine("parameters.Contains(path): {0}", parameters.Contains(path));
return "some url";
}
This is the code that is supposed to generate a URL, but altered to do
some tests instead. When I run it I get this in the console output:
...
Loads of xsp2 debug output
...
Parameters: {System.String controller = null, System.String path = /Page1, System.String action = null, System.String area = null}
path.GetHashCode(): 3433509
Key.GetHashCode(): 3433509
Key.Equals(path): True
ReferenceEquals(Key, path): False
Key == path: False
parameters.Contains(path): False
parameters.Contains(path): True
How could this possibly be? My current code is actually pretty trivial
as I have removed all but the bare minimum. I'm running Mono 2.6.3 as
available in Gentoo.
--
Simon Lindgren
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Detta =?ISO-8859-1?Q?=E4r?= en digitalt signerad
meddelandedel
Url : http://lists.ximian.com/pipermail/mono-list/attachments/20100422/e195c392/attachment.bin
More information about the Mono-list
mailing list