Wednesday, September 10, 2008

WF Error Correlation Token Already Initialized

Error


This is another error I ran into which I found really interesting.


System.InvalidOperationException: Correlation value on declaration "managerTaskToken" is already initialized. at System.Workflow.Runtime.CorrelationToken.Initialize(Activity activity, ICollection`1 propertyValues) at System.Workflow.Activities.CorrelationService.InvalidateCorrelationToken(Activity activity, Type interfaceType, String methodName, Object[] messageArgs) at System.Workflow.Activities.CallExternalMethodActivity.Execute(ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(T activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutor`1.Execute(Activity activity, ActivityExecutionContext executionContext) at System.Workflow.ComponentModel.ActivityExecutorOperation Run(IWorkflowCoreRuntime workflowCoreRuntime) at System.Workflow.Runtime.Scheduler.Run()


I did some and I found this rather quickly - http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/347537b5-7710-4576-98e9-fcd7b023ff0e/


Resolution


This error was really interesting to me and had to do with my lack of knowledge of the inner workings of WF. Here is a screenshot of an early iteration of sequential workflow I am creating.




In the workflow, the manager could reject back to the requestor and then the requestor will submit back to the manager for approval. Simple enough right? This error would occur after all of the resubmission events had completed and the state had gone back to the ManagerApproval state. What is happening is that I have different tasks created for each state which have their own tokens. To resolve the error make sure that on the CreateTask properties window that you select the name of the "state" for the OwnerActivityName and not the name of the "workflow" (in this case I select ManagerApproval). When the correlation token is set to the "state" it will be re-initialized when the state is created again (i.e. when the requestor resubmits back to the manager). The one thing to take note of is that once you do this the task cannot be reused in other states.

No comments: