Below is the code i am using getting key not present in the dictionary for status
EntityCollection EC = service.RetrieveMultiple(QE);
int total = EC.Entities.Count;
Console.WriteLine(total);
if(EC.Entities != null)
{
foreach(var ent in EC.Entities)
{
string casenumber = ent["ticketnumber"].ToString();
string casetitle = ent["title"].ToString();
Guid caseid = Guid.Parse(ent["incidentid"].ToString());
string id = caseid.ToString();
// Console.WriteLine("{0}\t{1}\t{2}", ++recordcount, casenumber, casetitle);
Entity resolution = new Entity("incidentresolution");
resolution["subject"] = "Closed";
resolution["incidentid"] = new EntityReference(ent.LogicalName,caseid);
CloseIncidentRequest closecase = new CloseIncidentRequest();
closecase.IncidentResolution = resolution;
closecase.Status = new OptionSetValue(5);
CloseIncidentResponse closeresponse = (CloseIncidentResponse)_service.Execute(closecase);
string status = ent.FormattedValues["statecode"];
Console.WriteLine("{0}\t{1}\t{2}\t{3}", ++recordcount, casenumber, casetitle,status);
}
}