I've only recently discovered the insert_recordset & update_recordset methods, and am trying to refactor a variety of procedural RBAR-style classes to use these methods, but appear to be hitting an issue on CIL compile when the X++ seems fine.
Scenario is that I've written an RDP class that populates a TempDB table (left as regular in the sample XPO below to more easily look at the data) with a record for the cartesian product of workers & dates within a range, and I want to get the worker's target hours for each day into the same temp DB table in order to compare hours worked to target. With target hours being an array field (as I understand it), I've got a loop that's intended to iterate through days of the week to identify the value, and I wanted to use update_recordset to update the table that holds the report data:
for(loopN = 1; loopN <- 7; loopN++)
{
update_recordSet tblData
setting
TargetHours = tblProjWorkerSetup.MaxWorkingHours[loopN]
outer join tblProjWorkerSetup where tbldata.WorkerRecId == tblProjWorkerSetup.Worker
&& tblData.DayNumber == loopN;
}
The X++ compiles fine, and using this approach in a job to sanity check for logic errors, all appears well. But when I run the incremental (or full) CIL compile, I get the error below in the log
Error 1. Class: RRH_DataProvider, Method: insertDataTmp, Exception: System.NotSupportedException: Line Number 43 - Stack empty. ---> System.InvalidOperationException: Stack empty.
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at Microsoft.Dynamics.Ax.Xpp.ILGenerator.Field(XmlNode node)
at ILGenerator::Field(ILGenerator , XmlNode )
at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelperGenerator.CallPCode(ILGenerator generator, String PCode, XmlNode node)
at Microsoft.Dynamics.Ax.Xpp.ILGenerator.processBytecode(XmlNode childNode)
--- End of inner exception stack trace ---
at Microsoft.Dynamics.Ax.Xpp.ILGenerator.processBytecode(XmlNode childNode)
at Microsoft.Dynamics.Ax.Xpp.ILGenerator.processBytecodes(TypeBuilder typeBuilder, XmlNode node)
at Microsoft.Dynamics.Ax.Xpp.ILGenerator.GenerateIL(TypeBuilder typeBuilder, XmlNode node)
at Microsoft.Dynamics.Ax.Xpp.ILGenerator.TraversePCode(XmlNode node)
at Microsoft.Dynamics.Ax.Xpp.PCodeTraverser.TraverseMethod(XmlNode methodNode)
at Microsoft.Dynamics.Ax.Xpp.ILGenerator.GenerateXppModule()
I've found innumerable blogs suggesting that a cleardown of the XPPIL folder & full recompile will solve issues like this, but I've tried that any number of times to no avail, so I've uploaded a small XPO that displays the issue in case I haven't explained myself sufficiently here.
Any thoughts greatly appreciated.