Hi Indrasena,
There are a few common reasons of this issue:
Reason 1: Please make sure you are mentioning the field name in Column Set in order to retrieve its value from CRM. For Example:
QueryExpression contactquery = new QueryExpression
{
EntityName="contact",
ColumnSet = new ColumnSet("firstname", "lastname", "contactid")
};
Here, I have mentioned only fields ("firstname", "lastname", "contactid") not the emailaddress but if f try to retrieve the value of emailaddress value, it will give Key Not found error.
Same thing applicable, when you are retrieving the data using service.Retrieve.
Reason 2: Trying to retrieve the unchanged field's value from the context. For Example, If my plugin is running on Update of Contact entity. I will get only updated/changed field values in COntext. If I will try to get the unchanged value I will get Key not found error.
Reason 3: Providing wrong attribute name while preparing entity object to create/Update the record in CRM. Especially in case of Late Binding, Provide the logical name of an attribute in lowercase (All chars should be in lower case).
Reason 4: Always check for Null or Empty value, while retrieving it's data:
For Example:
Entity accountentity = service.Retrieve("account", accountId, new ColumnSet(true));
if (accountentity.Attributes.Contains("new_account_id")&& accountentity.Attributes["new_account_id"]!=null)
{
}
Hope you get the root cause.
If my answer helped to resolve your issue, kindly verify it by clicking 'Yes'. It would be helpful to the other community members seeking to resolve a similar issue.
Cheers
Arpit
https://arpitmscrmhunt.blogspot.in