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.

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.


The ContainsKey method can be used to determine whether a key exists.

Community Additions