Exception of 'InvalidCastException' type - Calling EFx from BPM - 2022.2.8

Hey folks,

In an updatable BAQ I’m calling an Epicor function with a pot load of i/o arguments. 105 of them.

Before the function call, I explicitly set each argument variable in code to empty, 0, or false, depending on the type and then I set the inputs needed for this run. I don’t get a type error here.

The function runs okay. But when the function exits I get this Server Side Error in the BAQ’s BPM:

BPM runtime caught an unexpected exception of 'InvalidCastException' type.
See more info in the Inner Exception section of Exception Details.

Exception caught in: Epicor.ServiceModel

Error Detail 
============
Correlation ID:  afb01ad8-0e1d-495b-b8fb-47df0068a769
Description:  BPM runtime caught an unexpected exception of 'InvalidCastException' type.
See more info in the Inner Exception section of Exception Details.
Program:  System.Private.CoreLib.dll
Method:  ChkCast_Helper
Original Exception Type:  InvalidCastException
Server Trace Stack:     at Epicor.Customization.Bpm.Ubaq.GetListPostProcessingDirective_ValidateTestResults_DF0DD47EE2CF41968B8D97676342C6BC.A003_InvokeEpicorFunctionAction2()
   at Epicor.Customization.Bpm.Ubaq.GetListPostProcessingDirective_ValidateTestResults_DF0DD47EE2CF41968B8D97676342C6BC.ExecuteCore(Int32 step)
   at Epicor.Customization.Bpm.DirectiveBase`2.Execute() in C:\_releases\ICE\ICE4.2.200.8\Source\Server\Internal\Lib\Epicor.Customization.Bpm\DirectiveBase.Generic.cs:line 330
   at Epicor.Customization.Bpm.DirectiveBase`2.Execute(TParam parameters) in C:\_releases\ICE\ICE4.2.200.8\Source\Server\Internal\Lib\Epicor.Customization.Bpm\DirectiveBase.Generic.cs:line 222

Client Stack Trace 
==================
   at Ice.Cloud.ProxyBase`1.CallWithCommunicationFailureRetry(String methodName, ProxyValuesIn valuesIn, ProxyValuesOut valuesOut, RestRpcValueSerializer serializer)
   at Ice.Cloud.ProxyBase`1.CallWithMultistepBpmHandling(String methodName, ProxyValuesIn valuesIn, ProxyValuesOut valuesOut, Boolean useSparseCopy)
   at Ice.Cloud.ProxyBase`1.Call(String methodName, ProxyValuesIn valuesIn, ProxyValuesOut valuesOut, Boolean useSparseCopy)
   at Ice.Proxy.BO.DynamicQueryImpl.GetList(DynamicQueryDataSet queryDS, QueryExecutionDataSet executionParams, Int32 pageSize, Int32 absolutePage, Boolean& hasMorePage)
   at Ice.Adapters.DynamicQueryAdapter.<>c__DisplayClass45_0.<GetList>b__0(DataSet datasetToSend)
   at Ice.Adapters.DynamicQueryAdapter.ProcessUbaqMethod(String methodName, DataSet updatedDS, Func`2 methodExecutor, Boolean refreshQueryResultsDataset)
   at Ice.Adapters.DynamicQueryAdapter.GetList(DynamicQueryDataSet queryDS, QueryExecutionDataSet execParams, Int32 pageSize, Int32 absolutePage, Boolean& hasMorePage)
   at Ice.UI.App.BAQDesignerEntry.BAQTransaction.TestCallListBckg()
   at Ice.UI.App.BAQDesignerEntry.BAQTransaction.<>c__DisplayClass220_0.<BeginExecute>b__0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

Inner Exception 
===============
Unable to cast object of type 'System.Boolean' to type 'System.String'.

At the present time, I don’t have any widgets connected in the function. If I connect to a Raise Exception widget, I get that instead of the invalid cast exception box, so I think I know the function is working okay, and that the problem is when it tries to export the “out” portion of the argument list. Or it errors when the BAQ tries to import the list. Or something.

I’ve checked the argument list on the EFx widget in the BPM against the input and output lists on the function multiple times. I don’t get a mismatch when validating the BPM or on execution–just the invalid cast.

I’ve seen Epicor try its best guess at telling you what the problem is, and sometimes it doesn’t get it right. Maybe that’s the problem here? Maybe just too many dang arguments?

I put the guts of the function inside the BPM and it works just fine, so I don’t think it’s really a cast issue.

Grasping.

Thanks,

Joe

Ok first… I have got to see this, and I need to know everything. Spare no details. :rofl:

Ok, let’s get into it. I have come across bugs in the save routine for function signature. When it occurs, it’s seems to be only when editing, not initial load. It’s also inconsistent, which is nice.

The easiest way I have found to fix it is to export the library as an efxj, add .json on the end of it, and open it in VSCode. I then format it, and make sure the inputs and outputs of the function are in the right order and numbered appropriately.

This could also be you passing arguments from the bpm in the wrong order etc.

Looking at the error messages, it seems more like the error is in the BAQ BPM though.

Bill Murray Reaction GIF

Thanks, Kevin. I have a workaround for the moment until I can get back to it.

The reason for the many inputs–

We are validating test results for 23 chemical tests from a spectrometer. So that’s 23 element codes, 23 values, 23 result summaries, 23 pass fail flags, and a few other fields.

If the number of parameters is the issue I could change the function and pass in/out delimited lists.

Joe

JSON has the concept of arrays within an object that have other properties, which would fit nicely in this situation. Just a thought since it is being used more and more within Kinetic itself.

1 Like

Yes, I would pass JSON.

I don’t know if that’s what your issue is, but it would sure simplify calling it.

Any luck with this issue? Sorry, I know it’s been a long time. I am having the same issue myself and it’s only something happening in the UBAQ Designer not the function itself. I checked every parameter and variable and there is no invalid cast occurring but I still receive the error.

Just a hunch, but go export your library to a safe place.

Then reimport it with the force option.

Try again.

1 Like

I did this, no dice. I also test my function in postman and all is well with no errors. The issue is something in the BAQ designer but I can’t fix it. I am guessing I’ll have to either call the function through code or some other workaround rather than the invoke function widget.