0x80040265 The given key was not present in the dictionary

by Matt 30. July 2010 15:11

I'm writing a CRM 4.0 plugin and have encountered this error.  A bit of debugging helped me see what was going on.

First, make sure you check for the Target property on your context.InputParameters in your Execute method:

if (context.InputParameters.Properties.Contains("Target") && 
context.InputParameters.Properties["Target"] is DynamicEntity)

Finally, when you register steps on the plugin, make sure that you register the correct one!  My plugin is designed to deactivate existing entities based on specific criteria when new ones are created via data importing.  My problem was that although the code updates existing entities, it is supposed to run when a new entity is created.  Therefore, my step had to be registered as Create, not Update.

Finally, just as an extra layer of stability, I made sure to check the properties I needed on the Target entity before executing the logic:

if (entity.Properties.Contains("scc_branchplanid") &&
entity.Properties.Contains("scc_targetbranchnumber"))
Please Note:  I have had to disable comments on both of my blogs for the time being as a result of spammers.  I hope a solution in the near future will allow me to open the comments up again.
Tags: ,
Categories: CRM | C#