CRM 2015 QueryExpression System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary error

Entity object always return attributes with values. If your attribute doesn’t have value or there is a possibility always check. If not exists add it.

if (warrantyclaimproduct.Contains("new_linenum"))
                {
                    warrantyclaimproduct.Attributes["new_linenum"] = linenum;
                }
                else
                {
                    warrantyclaimproduct.Attributes.Add("new_linenum", linenum);
                }

Leave a Reply

Your email address will not be published. Required fields are marked *