Skip to content

Conversation

Copy link
Contributor

Copilot AI commented May 24, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original issue 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

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

Image

The exception is raising here.

Image

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

Image

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

Everything works well when I add this code snippet.

Image

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?

Fixes #6594.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


This change is Reviewable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LocalWorkflowClient.CreateAndRunInstanceAsync function raises System.NullReferenceException

2 participants