elsa-workflows / elsa-workflows/elsa-core
DispatchPendingWorkflowAsync method returns NullReferenceException
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
_Elsa version : 2.6.0_
Hello,
Excuse me for the long post that's coming.
I've been trying to use the method **DispatchPendingWorkflowAsync** and **CollectAndExecuteWorkflowsAsync** from the workflow launchpad service.
I am running 2 simple workflows (as in starting one -> it finishes; starting the second -> it finishes; and so on in random order)
For every of these 2 workflows I have a bookmark that gets executed in my code by calling the method CollectAndExecuteWorkflowsAsync.
First thing I observed after the method CollectAndExecuteWorkflowsAsync is called is that sometimes it created another new instance of the other workflow. All other instances were in status 2 - finished, no other workflow in pending.
So if I started workflow 1 -> CollectAndExecuteWorkflowsAsync is called -> CollectedWorkflows result gives 2 workflows (an instance for workflow 1 and a new instance for workflow 2) -> workflow 1 finished and a new instance with workflow 2 is created
**This is the code that I executed**:
```
var templateMessageContext = new WorkflowsQuery(nameof(SendMessage), new SendTemplateMessageBookmark(), workflowInstance.CorrelationId, workflowInstance.Id);
var templateMessageWorkflowInput = new WorkflowInput(message);
var collectedWorkflow = await _workflowLaunchpad.CollectAndExecuteWorkflowsAsync(templateMessageContext, templateMessageWorkflowInput, cancellationToken);
```
So after this, I started looking into the launchpad service and I tested a similar method, **DispatchPendingWorkflowAsync**:
```
var collectedWorkflow = new CollectedWorkflow(workflowInstance.Id, null);
await _workflowLaunchpad.DispatchPendingWorkflowAsync(collectedWorkflow, templateMessageWorkflowInput, cancellationToken);
```
then I received this exception at execution:
```
---> (Inner Exception #1) System.NullReferenceException: Object reference not set to an instance of an object.
at Elsa.Services.Workflows.WorkflowRunner.ResumeWorkflowAsync(WorkflowExecutionContext workflowExecutionContext, IActivityBlueprint activity, CancellationToken cancellationToken)
at Elsa.Services.Workflows.WorkflowRunner.RunWorkflowInternalAsync(WorkflowExecutionContext workflowExecutionContext, String activityId, CancellationToken cancellationToken)
at Elsa.Services.Workflows.WorkflowRunner.RunWorkflowAsync(IWorkflowBlueprint workflowBlueprint, WorkflowInstance workflowInstance, String activityId, WorkflowInput input, CancellationToken cancellationToken)
at Elsa.Services.Workflows.WorkflowResumer.ResumeWorkflowAsync(WorkflowInstance workflowInstance, String activityId, WorkflowInput input, CancellationToken cancellationToken)
at Elsa.Services.Workflows.WorkflowInstanceExecutor.ExecuteAsync(WorkflowInstance workflowInstance, String activityId, WorkflowInput input, CancellationToken cancellationToken)
at Elsa.Decorators.LockingWorkflowInstanceExecutor.ExecuteAsync(String workflowInstanceId, String activityId, WorkflowInput input, CancellationToken cancellationToken)
at Elsa.Decorators.LockingWorkflowInstanceExecutor.ExecuteAsync(String workflowInstanceId, String activityId, WorkflowInput input, CancellationToken cancellationToken)
at Elsa.Decorators.LockingWorkflowInstanceExecutor.ExecuteAsync(String workflowInstanceId, String activityId, WorkflowInput input, CancellationToken cancellationToken)
at Elsa.Services.Dispatch.Consumers.ExecuteWorkflowInstanceRequestConsumer.Handle(ExecuteWorkflowInstanceRequest message)
at Rebus.Pipeline.Receive.HandlerInvoker`1.Invoke()
at Rebus.Pipeline.Receive.DispatchIncomingMessageStep.Process(IncomingStepContext context, Func`1 next)
at Rebus.Sagas.LoadSagaDataStep.Process(IncomingStepContext context, Func`1 next)
at Rebus.Pipeline.Receive.ActivateHandlersStep.Process(IncomingStepContext context, Func`1 next)
at Rebus.Pipeline.Receive.HandleRoutingSlipsStep.Process(IncomingStepContext context, Func`1 next)
at Rebus.Pipeline.Receive.DeserializeIncomingMessageStep.Process(IncomingStepContext context, Func`1 next)
at Rebus.DataBus.ClaimCheck.HydrateIncomingMessageStep.Process(IncomingStepContext context, Func`1 next)
at Rebus.Pipeline.Receive.HandleDeferredMessagesStep.Process(IncomingStepContext context, Func`1 next)
at Rebus.Retry.FailFast.FailFastStep.Process(IncomingStepContext context, Func`1 next)
at Rebus.Retry.Simple.SimpleRetryStrategyStep.DispatchWithTrackerIdentifier(Func`1 next, String identifierToTrackMessageBy, ITransactionContext transactionContext, String messageId, String secondLevelMessageId)<---
```
I've been trying some debugging on it and the method _workflowInstanceDispatcher.DispatchAsync is giving the error.
Second observation (but maybe I'm wrong), I see that in Elsa 2.6.0 the CollectedWorkflow constructor has only 2 arguments. In the workflow launchpad service, CollectedWorkflow has 3 arguments.
Regardless of my untrained observations, could you please guide me towards some solution of this problem? Let me know if you need more information.
Thank you !!
Contributor guide
Assessment
This issue has not been assessed yet.