Just in case it helps someone, I'm posting the solution to this.
I found that to reproduce the issue I had to access a form table buffer, close the form, open it back up, and access the table buffer again. The error still wasn't 100% repeatable, but I could repeat it enough to get it to happen in the debugger. It's like the table buffer that the Addins use gets orphaned and not reinitialized correctly when the window is created again.
While in the debugger I was able to close the table and reinitialize the range for the form table buffer and get it working again. So the solution was:
SopLineWorkTable sopLineWork = SOPEntryForm.Tables.SopLineWork; try { sopLineWork.RangeClear(); sopLineWork.Key = 1; sopLineWork.Clear(); sopLineWork.SopNumber.Value = SOPNUMBE; sopLineWork.SopType.Value = 2; sopLineWork.LineItemSequence.Clear(); sopLineWork.RangeStart(); sopLineWork.LineItemSequence.Fill(); sopLineWork.RangeEnd(); te = sopLineWork.GetFirst(); } catch (Exception) { //if it fails it seems that closing the table and setting up the range fixes it //check all the items to make sure they have the correct shipping method Logging.Log.Instance.LogWarning("GetFirst threw exception, reinitializing the table buffer!"); sopLineWork.Close(); sopLineWork.RangeClear(); sopLineWork.Key = 1; sopLineWork.Clear(); sopLineWork.SopNumber.Value = SOPNUMBE; sopLineWork.SopType.Value = 2; sopLineWork.LineItemSequence.Clear(); sopLineWork.RangeStart(); sopLineWork.LineItemSequence.Fill(); sopLineWork.RangeEnd(); te = sopLineWork.GetFirst(); }
Make sure to leave the table buffer open and range setup correcly, otherwise the window could show all of the data in the table. Hopefully someone can find this useful.
Paul