delegateas/XrmMockup

Specified cast is not valid

catalin-ilie opened this issue · 2 comments

Describe the bug
It comes down to this code in WorkflowTree:

switch (TargetType)
{
case "Money":
dec1 = var1 is Money ? (var1 as Money).Value : (decimal)var1;
dec2 = var2 is Money ? (var2 as Money).Value : (decimal)var2;
break;
case "Int32":
dec1 = (int)var1;
dec2 = (int)var2;
break;
case "Decimal":
dec1 = (decimal)var1;
dec2 = (decimal)var2;
break;
default:
break;
}
when TargetType is "Decimal" and var1 is 100, what the code basically tries to do is:

object d = 100; var dd = (decimal)d;
this triggers the following Exception:

Error: Message: Specified cast is not valid.
StackTrace: at WorkflowExecuter.Arithmetic.Execute(Dictionary`2& variables, TimeSpan timeOffset, IOrganizationService orgService, IOrganizationServiceFactory factory, ITracingService trace) in C:\Users\ci\source\repos\XrmMockup\src\XrmMockupWorkflow\WorkflowTree.cs:line 466

Im not sure if this is due to how my metadata is rendered by CrmSvcUtils, but a fix would be to replace (decimal) with Convert.ToDecimal.

Resolved by PR #173

Added in 1.7.9