Archive for December, 2013

I ran into this exception today when trying to reconstruct a published form with a backup of its code-behind project. The exception and message was as follows:

“A first chance exception of type ‘System.Collections.Generic.KeyNotFoundException’ occurred in mscorlib.dll.The given key was not present in the dictionary.”

The project backup was a little out-of-date compared to the form, and  one of the secondary data connections that the form uses to write data back to a list had been renamed.

As a result, when it hit the line:

DataConnections[“<Name of Data Connection>”].Execute();

it blew up and threw the exception. After a little bit of head-scratching, I noticed that the name of the data connection had changed, so simply renaming it in code took care of the problem.