elsa-workflows / elsa-workflows/elsa-core

LocalWorkflowClient.CreateAndRunInstanceAsync function raises System.NullReferenceException

Open
#6,594 1 comment 1 reaction 1 assignee Assigned to @Copilot View on GitHub
triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

We have ASP.NET Core Web API application which is based on .NET 8. This application uses Elsa Workflows NuGets 3.3.0-rc7. Everything works well with this configuration. But... when we update NuGets, we get System.NullReferenceException from LocalWorkflowClient.CreateAndRunInstanceAsync function. We tried all versions up to 3.3.5 and got the same exception.

I will try to describe what exactly we do. We create a root activity which in turn includes other activities as a children. All these activities are creating by our own code. We don't use any builders from Elsa Workflows NuGets. Then, we save Elsa Workflows definition to a database as you can see it below on the figure.

![Image](https://github.com/user-attachments/assets/0b8289b7-87a6-4605-966f-48daa2c07bee)

If Elsa Workflows definition has been saved in a database successfully, we try to create and run a workflow.

![Image](https://github.com/user-attachments/assets/abac3b4b-9a05-4459-b506-479d89c2905b)

The exception is raising here.

![Image](https://github.com/user-attachments/assets/004d1938-3e81-4964-87b3-f25dd266fe80)

After my investigation, I found out that this private field doesn't have any items.

![Image](https://github.com/user-attachments/assets/fbb34ea6-88aa-4850-a2f2-88ed9c7d0eca)

Due to it, functionality can't find any `ActivityDescriptor` during workflow instantiation.

Everything works well when I add this code snippet.

![Image](https://github.com/user-attachments/assets/75aa77c9-de78-4b23-84f1-601228e586cd)

Because, after that, `_activityDescriptors` private field contains items. The field will be filled in too if you open any workflow definitions in Elsa Workflows Dashboard firstly.

The stack trace is...

```
at Elsa.Workflows.ActivityFactory.ReadSyntheticInputs(ActivityDescriptor activityDescriptor, IActivity activity, JsonElement activityRoot, JsonSerializerOptions options)
at Elsa.Workflows.ActivityFactory.Create(Type type, ActivityConstructorContext context)
at Elsa.Workflows.Serialization.Converters.ActivityJsonConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo`1 jsonTypeInfo, Nullable`1 actualByteCount)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo`1 jsonTypeInfo)
at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
at Elsa.Workflows.Serialization.Serializers.JsonActivitySerializer.Deserialize(String serializedActivity)
at Elsa.Workflows.Management.Mappers.WorkflowDefinitionMapper.Map(WorkflowDefinition source)
at Elsa.Workflows.Management.Materializers.JsonWorkflowMaterializer.ToWorkflow(WorkflowDefinition definition)
at Elsa.Workflows.Management.Materializers.JsonWorkflowMaterializer.MaterializeAsync(WorkflowDefinition definition, CancellationToken cancellationToken)
at Elsa.Workflows.Management.Services.WorkflowDefinitionService.MaterializeWorkflowAsync(WorkflowDefinition definition, CancellationToken cancellationToken)
at Elsa.Workflows.Management.Services.WorkflowDefinitionService.FindWorkflowGraphAsync(WorkflowDefinitionFilter filter, CancellationToken cancellationToken)
at Elsa.Workflows.Management.Services.WorkflowDefinitionService.FindWorkflowGraphAsync(WorkflowDefinitionHandle definitionHandle, CancellationToken cancellationToken)
at Elsa.Workflows.Runtime.LocalWorkflowClient.GetWorkflowGraphAsync(WorkflowDefinitionHandle definitionHandle, CancellationToken cancellationToken)
at Elsa.Workflows.Runtime.LocalWorkflowClient.CreateInstanceInternalAsync(CreateWorkflowInstanceRequest request, CancellationToken cancellationToken)
at Elsa.Workflows.Runtime.LocalWorkflowClient.CreateAndRunInstanceAsync(CreateAndRunWorkflowInstanceRequest request, CancellationToken cancellationToken)
```

Could you please tell me what we are doing wrong or if it is a bug?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.