I am trying to get the approval status for each activity of the workflow process history item as below.
var status = csClient.Read(activitiydetails.Id, readoption) as ApprovalStatusData;
logdetails("Activity Approval Status--->" + status.Title.ToString());
I am getting "object reference error"
When you use the As
operator to cast to ApprovalStatusData
, you should expect that if the object returned from csClient.Read()
is not an ApprovalStatusData
, its value will be null. When you then try to use it on the following line, you will get an object reference error.
It seems likely from the fact that your variable is called activitiydetails
[sic] that you shouldn't be expecting an ApprovalStatusData
to be returned.
If you write the code with the correct Cast operator, the code will fail when you try to cast, and throw an InvalidCastException.
var status = (ApprovalStatusData)csClient.Read(activitiydetails.Id, readoption);
logdetails("Activity Approval Status--->" + status.Title.ToString());