BPM runtime caught an unexpected exception of 'NullReferenceException' type

Need some help.

We are getting the following error:
Server Side Exception

BPM runtime caught an unexpected exception of ‘NullReferenceException’ type.
See more info in the Inner Exception section of Exception Details.

Exception caught in: Epicor.ServiceModel

Error Detail

Description: BPM runtime caught an unexpected exception of ‘NullReferenceException’ type.
See more info in the Inner Exception section of Exception Details.
Program: Erp.Services.BO.ARInvoice.dll
Method: InvcDtlBeforeUpdate
Line Number: 14184
Column Number: 13
Original Exception Type: NullReferenceException
Server Trace Stack: at Erp.Services.BO.ARInvoiceSvc.InvcDtlBeforeUpdate() in C:_Releases\ERP\UD10.2.200.23\Source\Server\Services\BO\ARInvoice\ARInvoice.cs:line 14184
at Ice.Services.Trace.TablesetProfilingCollector.DoRowEventTrace(String tableName, String methodName, Int32 rowCount, Action action) in C:_Releases\ICE\RL3.2.200.0\Source\Framework\Epicor.Ice\Services\TablesetProfilingCollector.cs:line 144
at Ice.TablesetBound3.UpdateRow(IceDataContext dataContext, Int32 tableNum, IIceTable table, IceRow updatedRow, IceRow originalRow, TablesetProfilingCollector parentTraceCollector) in C:\_Releases\ICE\RL3.2.200.0\Source\Framework\Epicor.Ice\Services\TablesetBound.cs:line 1279 at Ice.TablesetBound3.WriteTable(IceDataContext dataContext, Int32 tableIndex, IIceTable table, TablesetProfilingCollector parentTraceCollector) in C:_Releases\ICE\RL3.2.200.0\Source\Framework\Epicor.Ice\Services\TablesetBound.cs:line 997
at Ice.TablesetBound3.InnerUpdate[TUpdater](IceDataContext dataContext, TFullTableset tableset) in C:\_Releases\ICE\RL3.2.200.0\Source\Framework\Epicor.Ice\Services\TablesetBound.cs:line 900 at Erp.Services.BO.ARInvoiceSvc.Update(ARInvoiceTableset& ds) in C:\_Releases\ERP\UD10.2.200.23\Source\Server\Services\BO\ARInvoice\ARInvoice.Designer.cs:line 4233 at Erp.Services.BO.ARInvoiceSvcFacade.Update(ARInvoiceTableset& ds) in C:\_Releases\ERP\UD10.2.200.23\Source\Server\Services\BO\ARInvoice\ARInvoiceSvcFacade.cs:line 9613 at Epicor.Customization.Bpm.BO13CD3D75C253472D912321576BF67A33.GetListPreProcessingDirective_Update_DTD_Misc_Charge_on_Partial_Shipments_A7ABAEED89684CC6AF1D1CE44BE7E7D3.A001_CustomCodeAction() at Epicor.Customization.Bpm.BO13CD3D75C253472D912321576BF67A33.GetListPreProcessingDirective_Update_DTD_Misc_Charge_on_Partial_Shipments_A7ABAEED89684CC6AF1D1CE44BE7E7D3.ExecuteCore() at Epicor.Customization.Bpm.DirectiveBase3.Execute(TParam parameters) in C:_Releases\ICE\ICE3.2.200.23\Source\Server\Internal\Lib\Epicor.Customization.BPM\DirectiveBase.Generic.cs:line 147

Client Stack Trace

at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets)
at Erp.Proxy.BO.ARInvoiceImpl.GetList(String whereClause, Int32 pageSize, Int32 absolutePage, Boolean& morePages)
at Erp.Adapters.ARInvoiceAdapter.OnGetList(String whereClause, SearchOptions opts, Boolean& MorePages)
at Ice.Lib.Framework.EpiBaseAdapter.GetList(SearchOptions opts, Boolean& morePages)
at Ice.Lib.Searches.EpiSearchEngine.GetSearchResultsFromAdapterMethod(SearchOptions opts, SearchDataSetMode sdsMode)
at Ice.Lib.Searches.EpiSearchEngine.SearchUsingAdapterMethod(SearchOptions options)
at Ice.Lib.Searches.EpiSearchEngine.SearchIt(SearchOptions options, DataSet& results, Boolean& usedAdapter)
at Ice.Lib.Searches.EpiSearchEngine.SearchIt(SearchOptions options)
at Ice.Lib.Framework.EpiBaseAdapter.InvokeSearch(SearchOptions opts)
at Erp.Adapters.ARInvoiceAdapter.InvokeSearch(SearchOptions opts)
at Erp.UI.App.ARInvoiceEntry.Transaction.invGetList(String groupID)

Inner Exception

Object reference not set to an instance of an object.

With the code below:
var ARInvSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.ARInvoiceSvcContract>(Db);
var ds = new Erp.Tablesets.ARInvoiceTableset();

foreach (int Invoice in InvoiceList)
  using (var txScope = IceDataContext.CreateDefaultTransactionScope())
    ds = ARInvSvc.GetByID(Invoice);
    foreach (var id in (from i in ds.InvcDtl where i.SellingShipQty != i.SellingOrderQty select i))
    if (id != null)
      var ID_Row = id;
      ID_Row.RowMod = IceRow.ROWSTATE_UPDATED;
      ARInvSvc.OnChangeofLineDiscAmt(ID_Row.InvoiceNum, ID_Row.InvoiceLine, 10, ref ds);
      Epicor.Customization.Bpm.InfoMessage.Publish("InvcDtl.RowMod = " + ID_Row.RowMod.ToString() + ". ");

The assignment of RowMod is giving us the error. Can someone please help us with this issue?

Thanks in advance

Has anyone else ran into an issue like this?

I dont know the particular issue but I have a few comments\questions.

How do you know the setting of the RowMod is causing the failure?
Are you completing each TransactionScope?

Here is how I would write it:

foreach (int Invoice in InvoiceList)
  using (var txScope = IceDataContext.CreateDefaultTransactionScope())
    ds = ARInvSvc.GetByID(Invoice);
    if(ds == null || ds.InvcDtl == null) continue;
    foreach (var id in ds.InvcDtl.Where(i => i.SellingShipQty != i.SellingOrderQty ))
      id.RowMod = IceRow.ROWSTATE_UPDATED;
      ARInvSvc.OnChangeofLineDiscAmt(id.InvoiceNum, id.InvoiceLine, 10, ref ds);

I assume you are writing the changes made by OnChangeOfLineDiscAmt back to the DB?

1 Like

If we comment out id.RowMod = IceRow.ROWSTATE.UPDATED; error doesn’t pop up.

Invoice Detail table is resulting values, as in the code beneath this, we are using InvoiceNum and InvoiceLine values to update the InvcMisc table.

Yes, we are trying to update the DB with the changes made by OnChangeOfLineDiscAmt. If the value of RowMod is not updated, OnChangeOfLineDiscAmt errors with InvcDtl not found.

Have you used that as an assignment before? Every example I have sets RowMod to “U” or “D”

I only use Updated in a query.

I have used assignment before and I have assignment in this BPM code itself, which works. I have tried assigning “U” and what Chris suggested. Both of them gives an error.

I know this is a very old thread but I just now came across the question. I’m giving an answer in case someone else comes across this problem. The answer, I believe, is the way you are loading the table.

Erp.Tableset (the actual table) does not have a RowMod field; rather, the temporary table does. So you’d want to get the temporary instance of a table, for example:

foreach (var ttInvcDtl_iterator in (from ttInvcDtl_Row in ttInvcDtl
where ttInvcDtl_Row.SellingShipQty != ttInvcDtl_Row.SellingOrderQty
select ttInvcDtl_Row))
var ttInvcDtlRow = ttInvcDtl_iterator;

// Do data updates here

// Notice I’m creating a pointer to the table using the tableset, it is not necessary within the BPM for Invoice. I typically only use the erp.tableset if I’m reading data and not writing to it like OrderHed or Customer from here - though it is possible.

I also just wanted to add, the code I listed will only find the record that is currently in memory so it can’t be used for what you are trying to do. The point is, there is no RowMod in the “original” table.

The explanation for this error and the solution is posted here: BPM ARInvoice Error - Update Tax Category - #7 by hkeric.wci