Troubleshooting Exceptions: System.Collections.Generic.KeyNotFoundException
A KeyNotFoundException is thrown when an attempt is made to retrieve a key or key value pair from a collection using a nonexistent key.
Associated Tips
- Check that the key you are using exists in the collection you are attempting to access.
This exception occurs when an operation attempts to retrieve an element in a collection using a key that does not exist in that collection.
Remarks
The ContainsKey method can be used to determine whether a key exists.
See Also
Tasks
How to: Use the Exception Assistant