elsa-workflows / elsa-workflows/elsa-core
NullReferenceException When Creating Workflows with Custom EF Core Migrations in Elsa 3.4.0
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
## Description
When using Elsa 3.4.0 with custom database contexts and migrations (with runMigrations set to false), attempting to create a workflow after manually updating the database with dotnet ef results in a System.NullReferenceException with a reference to NotFoundActivity. The workflow creation succeeds only when allowing Elsa to manage its own migrations (runMigrations set to true).
## Environment
- **Elsa Package Version**: 3.4.0
- **Operating System**: Windows.
- **Browser and Version**: Chrome.
## Reproduction Steps
- Set up a solution with separate Elsa Server and Elsa Studio components
- Implement custom database contexts and factories for runtime and management modules
- Configure Elsa with runMigrations set to false
- Apply migrations manually using dotnet ef database update
- Attempt to create a workflow in Elsa Studio
## Expected Behavior
Workflow creation should succeed regardless of whether migrations are managed internally by Elsa or externally via dotnet ef.
## Actual Behavior
A NullReferenceException is thrown when attempting to create a workflow, preventing successful workflow creation when using custom migrations.
## Log Output
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.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
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.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
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, T& value, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.ContinueDeserialize(ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack, T& value)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsync(Stream utf8Json, CancellationToken cancellationToken)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsObjectAsync(Stream utf8Json, CancellationToken cancellationToken)
at FastEndpoints.RequestBinder`1.BindJsonBody(HttpRequest httpRequest, JsonSerializerContext serializerCtx, CancellationToken ct)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
## Workaround
Setting runMigrations to true and allowing Elsa to handle migrations internally resolves the issue, but prevents the use of custom migration management.
## Related Issues
Potentially related to issue #6804 in the Elsa repository.
## Sample Repository
https://github.com/uyarbtrlp/ElsaExample
Contributor guide
Assessment
This issue has not been assessed yet.