You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
---> System.InvalidOperationException: The requested operation requires an element of type 'Object', but the target element has type 'Number'.
at System.Text.Json.ThrowHelper.ThrowJsonElementWrongTypeException(JsonTokenType expectedType, JsonTokenType actualType)
at System.Text.Json.JsonElement.EnumerateObject()
at Elsa.Workflows.Core.Serialization.Converters.PolymorphicObjectConverter.Write(Utf8JsonWriter writer, Object value, JsonSerializerOptions options)
Version
Elsa V3.0.0-preview.906
Steps to reproduce
Run a workflow that has an Expando object variable. Then assign a Decimal to the expando. Run the workflow.
This workflow demonstrates the issue:
public class IffyWorkflow : WorkflowBase
{
protected override void Build(IWorkflowBuilder builder)
{
var document = builder.WithVariable<ExpandoObject>();
builder.Root = new Sequence
{
Activities =
{
new Inline(context =>
{
dynamic boom = new ExpandoObject();
boom.Ok = "456";
boom.AlsoOk = 456;
boom.NotOk = 456m;
context.Set(document,boom);
}),
new Finish()
}
};
}
}
Result
Execution of the JsonWorkflowStateSerializer will eventually cause the above exception to be thrown and the WorkflowInstance table wont be updated.
Cause
Decimals aren't Primitives. When Elsa.Workflows.Core.Serialization.Converters.PolymorphicObjectConverter tests using if (type.IsPrimitive || value is string or DateTimeOffset or DateTime or DateOnly or TimeOnly or JsonElement or Guid or TimeSpan or Uri or Version or Enum) false is returned.
Execution will continue to foreach (var property in jsonElement.EnumerateObject().Where(property => !property.NameEquals(TypePropertyName))) which causes the exception as the value isn't an Object either.
The text was updated successfully, but these errors were encountered:
chris-sargood
changed the title
PolymorphicObjectConverter InvalidOperationException thrown
PolymorphicObjectConverter throws InvalidOperationException for decimals
Dec 19, 2023
Hi,
We're getting the following exception thrown:
Exception Details
Version
Elsa V3.0.0-preview.906
Steps to reproduce
Run a workflow that has an Expando object variable. Then assign a Decimal to the expando. Run the workflow.
This workflow demonstrates the issue:
Result
Execution of the
JsonWorkflowStateSerializer
will eventually cause the above exception to be thrown and theWorkflowInstance
table wont be updated.Cause
Decimals aren't Primitives. When
Elsa.Workflows.Core.Serialization.Converters.PolymorphicObjectConverter
tests usingif (type.IsPrimitive || value is string or DateTimeOffset or DateTime or DateOnly or TimeOnly or JsonElement or Guid or TimeSpan or Uri or Version or Enum)
false is returned.Execution will continue to
foreach (var property in jsonElement.EnumerateObject().Where(property => !property.NameEquals(TypePropertyName)))
which causes the exception as the value isn't an Object either.The text was updated successfully, but these errors were encountered: