elsa-workflows / elsa-workflows/elsa-core
Issue when passing List<object> as input to ForEach activity in elsa workflow
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
I am passing List as input to ForEach activity.
While running workflow below exception is thrown:
An exception was thrown whilst setting 'ForEach.Items'. See the inner exception for further details.
---> Elsa.Exceptions.ExpressionEvaluationException: Failed to evaluate expression
---> System.InvalidCastException: Object must implement IConvertible.
Example:
**Activity A**
[ActivityOutput(Hint = "")]
public List OutputData { get; set; } = new List();
//[{"Name":"Vartika Sharma3","EmailAddress":"vs@gmail.com","Address":"Ahmedabad","SSN":"2222222"},{"Name":"Vartika //Sharma2","EmailAddress":"vs@gmail.com"}]
**Activity B** : ForEach

Below attached exception is throwing:

Elsa.Exceptions.CannotSetActivityPropertyValueException: An exception was thrown whilst setting 'ForEach.Items'. See the inner exception for further details.
---> Elsa.Exceptions.ExpressionEvaluationException: Failed to evaluate expression
---> System.InvalidCastException: Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType)
at Elsa.Scripting.JavaScript.Services.ConvertChangeTypeResultConverter.ConvertToDesiredType(Object evaluationResult, Type desiredType)
at Elsa.Scripting.JavaScript.Services.PlainObjectResultConverter.ConvertToDesiredType(Object evaluationResult, Type desiredType)
at Elsa.Scripting.JavaScript.Services.EnumerableResultConverter.ConvertToDesiredType(Object evaluationResult, Type desiredType)
at Elsa.Scripting.JavaScript.Services.ExpandoObjectToDictionaryWhenNoDesiredTypeResultConverter.ConvertToDesiredType(Object evaluationResult, Type desiredType)
at Elsa.Scripting.JavaScript.Services.TypeConverterResultConverter.ConvertToDesiredType(Object evaluationResult, Type desiredType)
at Elsa.Scripting.JavaScript.Services.NullResultConverter.ConvertToDesiredType(Object evaluationResult, Type desiredType)
at Elsa.Scripting.JavaScript.Services.JintJavaScriptEvaluator.EvaluateAsync(String expression, Type returnType, ActivityExecutionContext context, Action`1 configureEngine, CancellationToken cancellationToken)
at Elsa.Scripting.JavaScript.Services.JavaScriptExpressionHandler.EvaluateAsync(String expression, Type returnType, ActivityExecutionContext context, CancellationToken cancellationToken)
at Elsa.Expressions.ExpressionEvaluator.EvaluateAsync(String expression, String syntax, Type returnType, ActivityExecutionContext context, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at Elsa.Expressions.ExpressionEvaluator.EvaluateAsync(String expression, String syntax, Type returnType, ActivityExecutionContext context, CancellationToken cancellationToken)
at Elsa.Services.Workflows.ExpressionActivityPropertyValueProvider.GetValueAsync(ActivityExecutionContext context, CancellationToken cancellationToken)
at Elsa.Services.ActivityPropertyProviders.SetActivityPropertiesAsync(IActivity activity, ActivityExecutionContext activityExecutionContext, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at Elsa.Services.ActivityPropertyProviders.SetActivityPropertiesAsync(IActivity activity, ActivityExecutionContext activityExecutionContext, CancellationToken cancellationToken)
at Elsa.Services.Workflows.ActivityActivator.ActivateActivityAsync(ActivityExecutionContext context, Type type, CancellationToken cancellationToken)
at Elsa.Providers.ActivityTypes.TypeBasedActivityProvider.<>c__DisplayClass6_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Elsa.Services.Workflows.WorkflowRunner.RunCoreAsync(WorkflowExecutionContext workflowExecutionContext, ActivityOperation activityOperation, CancellationToken cancellationToken)
at Elsa.Services.Workflows.WorkflowRunner.RunCoreAsync(WorkflowExecutionContext workflowExecutionContext, ActivityOperation activityOperation, CancellationToken cancellationToken)
at Elsa.Services.Workflows.WorkflowRunner.RunAsync(WorkflowExecutionContext workflowExecutionContext, ActivityOperation activityOperation, CancellationToken cancellationToken)
Version I am using is 2.4.0.1
Contributor guide
Research direction
Reproduce the ForEach.Items evaluation using the List example on Elsa 2.4.0.1. Start with Elsa.Scripting.JavaScript.Services.ConvertChangeTypeResultConverter and EnumerableResultConverter from the stack trace, then trace the evaluation through JintJavaScriptEvaluator; done means the workflow accepts the list without InvalidCastException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100