“The given key was not present in the dictionary” KeyNotFoundException Exception in CRM 2016


I had just done this

  1. Created a new Schema attribute called MyGroupList of DataType OptionList with 2 options in the list, Option A and Option B. The purpose being I want to further designate the group based on department.
  2. Added to the Market list form [Appears in creation and Edit]
  3. For 5 of my Market Lists I selected Option A
  4. Write C# code to query for contacts that belong to market lists where MygroupList = option A


Then I get the error “The given key was not present in the dictionary”.

Problem cause

I think this may be…

  1. I got the schema name wrong. I checked and well its sort of wrong in my code, I didn’t know Dynamics appends “new” to my mygrouplist. I make the change, same error.
  2. Perhaps the Webservice has not been updated. Restart the CRM services. Same error.
  3. Reboot the server, same error.

Okay, here is the problem, you have to check that there is a value for other groups, for my 50+ other groups that did not have a value when the code gets to it says “The given key was not present in the dictionary” and stops.

The Solution

So I had to do an IsPresent,

If (new_mygrouplist.IsPresent)


If (new_mygrouplist.value = Option A)


Do xyz



For more info on Managing Identities in Dynamics CRM, I will be giving a presentation on the MIM Usergroup on April 11th.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s