I'm trying to query a running state machine workflow using StateMachineWrokflowInstance
in ASP.NET MVC.
Here is the scenario:
-
Workflow runtime configuration: added
SqlWorkflowPersistenceService
,ManualWorkflowSchedulerService
,ExternalDataExchangeService
and registered customExternalDataExchange
service withExternalDataExchangeService
; -
Execution sequence:
var instance = WorkflowRuntimeHandle.CreateWorkflow(type); instance.Start(); WorkflowRuntimeHandle.GetService<ManualWorkflowSchedulerService> ().RunWorkflow(instance.InstanceId); var stateMachineWorkflowInstance = new StateMachineWorkflowInstance(instance.WorkflowRuntime, instance.InstanceId);
-
Received error:
System.InvalidOperationException: Workflow with id "[GUID]" not found in state persistence store?
What am I doing wrong?
Best Answer
Apparently this exception could have many causes.
I found a way to detect the culprit. I added handlers for all the workflow runtime events and stored the sequence as history in a list and discovered from the list that after
RunWorkflow
is called the workflow was terminated.The
WorkflowTerminated
event parameterWorkflowTerminatedEventArgs
comes with aException
property which includes inner exceptions that showed the real source of the problem.I'm posting this here in hope that this experience would be beneficial to those who are reading.