2011-04-09

troubleshooting in making workflow each steps (InvalidOperationException and ArgumentNullException)

This time, I introduce how to make simple workflow and its troubleshooting.
Someone who makes workflow encounter a few exceptions. I show each resolutions when workflow execution.


  • Make Sequential Workflow from SharePoint 2010 template.


  • Make simple workflow. CreateTask, Delay, and CompleteTask.

  • Set correlation Token same as onWorkflowActivated1 for createTask1 and completeTask1 in each properties menu.
onWorkflowActivated1 : workflowToken
createTask1              : workflowToken
completeTask1           : workflowToken
  • Build, deploy and run in particular list. Of course, It doesn't work. 


I checked ULSlog and found bellow InvalidOperationException about workflow.

System.InvalidOperationException:
Correlation value on declaration "workflowToken" 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()

This error is little bit tricky.
What we need to do is using new correlation token for each set of createTask and completeTask.
onWorkflowActivated1 : workflowToken
createTask1              : TaskToken1
completeTask1           : TaskToken1


We use orrelation token to identify each tasks. If you have two tasks in workflow, you can set here.

onWorkflowActivated1 : workflowToken
createTask1              : TaskToken1
completeTask1           : TaskToken1
createTask2              : TaskToken2
completeTask2           : TaskToken2

  • Let's build, deploy and run again !  But,, you still get ArgumentNullException...
System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null.  
at Microsoft.SharePoint.Workflow.SPWorkflow.GetReservedItemId(SPList list, Guid taskId, Boolean createNew)  
at Microsoft.SharePoint.Workflow.SPWorkflow.GetReservedItemId(SPList list, Guid taskId)  
at Microsoft.SharePoint.Workflow.SPWinOETaskService.CreateTaskWithContentTypeInternal(Guid taskId, SPWorkflowTaskProperties properties, Boolean useDefaultContentType, SPContentTypeId ctid, HybridDictionary specialPermissions)  
 at Microsoft.SharePoint.Workflow.SPWinOETaskService.CreateTask(Guid taskId, SPWorkflowTaskProperties properties, HybridDictionary specialPermissions)  
--- End of inner exception stack trace ---  
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)  
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)  
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)  
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)     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()

It seems that this error occurs when createTask execute.
In here, What we need to do is setting new GUID for createTask.

  • Double-click "TaskId" in createTask1 properties. and make new Field which bind TaskId.


You can find bellow code is generated.

public Guid createTask1_TaskId1 = default(System.Guid);



  • Double-click "TaskProperties" in createTask1 properties. and make new Field which bind TaskProperties.


You can find bellow code is generated.

public SPWorkflowTaskProperties createTask1_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();


  • Double click onWorkflowActivated1 and write code in onWorkflowActivated1_Invoked like this.

private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
    this.workflowId = workflowProperties.WorkflowId;
}

  • Double click createTask1 and write code in createTask1_MethodInvoking like this.

private void createTask1_MethodInvoking(object sender, EventArgs e)
{
    this.createTask1_TaskId1 = Guid.NewGuid();
    this.createTask1_TaskProperties1.Title = "Please approve the document.";
    this.createTask1_TaskProperties1.AssignedTo = "domain\\someone";
}



  • Let's build, deploy and run again !
done.... It's heavy work.



So, this time is spring. We can see a lot of cherry blossoms. enjoy now !!



3 comments:

  1. Good article !

    Just an edit. You forgot a "c" in "We use orrelation token..." ;)

    ReplyDelete
  2. Really thx for this article!!!

    WL.

    ReplyDelete
  3. 御苦労様, this helped a lot

    ReplyDelete