AfterProperties.PercentCompleted: Input string was not in correct format.

A small tip while using the OntaskChanged activity, if you want to check if the assigned has completed his task don't use the AfterProperties.PercentComplete property .

Problematic situation:
A user modifies the task and the OntaskChanged_Invoked eventhandler is triggered. In this eventhandler the system checks is the user completed the task by setting the PercentCompleted formfield.
When the user doesn't uses the PercentCompleted field, but he uses the Status field. The workflow will crash because the code that is written behind the PercentComplete property of the AfterProperties object uses the StringToNumber(…) method.

//This will crash if the user leaves percentcomplete empty
string perComp = AfterProperties.PercentComplete;

Solution
AfterProperties contains a hashtable called ExtendedProperties, this hashtable has a guid as key(these guids can be found here ) and the current value as a string.By using this hashtable the system can first check if the Guid is available and if the stringvalue is valid.

//Get the percentcompleted value of the task by using the hashtable   
string perComp = AfterProperties.ExtendedProperties(Microsoft.SharePoint.SPbuiltInFieldId.PercentComplete);
if(String.IsNullOrEmpty(perComp)){
...

You should also check if the user didn't use the status combobox to set his task as completed.

//Get the status value of the task by using the hashtable
string status= AfterProperties.ExtendedProperties(Microsoft.SharePoint.SPbuiltInFieldId.TaskStatus);
if(status == "Completed"){
...
VN:F [1.9.22_1171]
Rating: 10.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
AfterProperties.PercentCompleted: Input string was not in correct format., 10.0 out of 10 based on 1 rating