elsa-workflows / elsa-workflows/elsa-core
forach in code can result in an exception
- Dominant language
- C#
- Stars
- 7.9k
- Forks
- 1.5k
- Avg merge
- 15h 22m
- Merged PRs (30d)
- 114
Description
The Exception
```csharp
Elsa.Exceptions.TypeConversionException
HResult=0x80131500
Message=Failed to convert an object of type Workflows.ForEachIssue+GridAreaTest to System.Collections.Generic.List`1[Workflows.ForEachIssue+GridAreaTest]
Source=Elsa.Abstractions
StackTrace:
at Elsa.ObjectConverter.ConvertTo(Object value, Type targetType)
at Elsa.ObjectConverter.ConvertTo[T](Object value)
at Elsa.Services.Models.ActivityExecutionContext.GetInput[T]()
at Workflows.ForEachIssue.<>c.b__0_0(ActivityExecutionContext context) in
at Elsa.Activities.ControlFlow.ForEachBuilderExtensions.<>c__DisplayClass1_0`1.b__2(ActivityExecutionContext context)
at Elsa.Builders.SetupActivityExtensions.<>c__DisplayClass6_0`2.b__0(ActivityExecutionContext context)
at Elsa.Builders.SetupActivity`1.<>c__DisplayClass6_0`1.<b__0>d.MoveNext()
This exception was originally thrown at this call stack:
[External Code]
Inner Exception 1:
InvalidCastException: Object must implement IConvertible.
````
Workflow
```csharp
public class ForEachIssue : IWorkflow
{
public void Build(IWorkflowBuilder builder)
{
_ = builder.
SignalReceived("foreachIssue")
.ForEach(context => context.GetInput>(), item =>
{
item.SendSignal(signal =>
signal
.WithSignal("issue")
.WithInput(context => context.Input));
}).WithDisplayName($"foreach grid area");
}
public class GridAreaTest
{
public string Id { get; set; } = string.Empty;
}
}
```
Input for the signal
```json
{
"correlationId": "demo",
"input": [
{
"id": "6"
},
{
"id": "demo"
}
]
}
```
Contributor guide
Assessment
This issue has not been assessed yet.