vb.netdictionaryasp.net-2.0keynotfoundexception

KeyNotFoundException when a Key with the requested value exists in VB.NET ASP.NET 2.0 Dictionary


Debug Session Image The ValueList variable is defined as Dictionary(Of String, String)

The watch values captured show the data (tmpData) has a value of "1".

The ValueList is defined such that the replacement value for "1" is "Project Resource" as can be seen form the expansion of the SSGCol.ValueList Watch variable.

However, when I try to access the value I receive a KeyNotFoundException

I have done this sort of thing thousands of times in the past, but for some reason today I cannot get it to work. I must be missing something really obvious and need someone to take a fresh look and give me a slap when they see my obvious mistake.


Solution

  • Perhaps there are some unprintable characters in the string. Try comparing the bytes in the strings, for instance:

    Dim bytes() As Byte = System.Text.Encoding.Unicode.GetBytes(tmpData)