Why am I getting this exception

I have a System.Data.DataSet and one separate table. The table has many columns.

Screenshot of the DataSet Designer

In the event handler, I set the decimal value for one of the fields in an existing data row (during installation).

In a very rare case, I get an exception ArgumentOutOfRangeException.

Message: System.ArgumentOutOfRangeException: The index was out of range. Must be non-negative and smaller than the size of the collection.

Call stack:

   at System.ThrowHelper.ThrowArgumentOutOfRangeException()
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at System.Data.RecordManager.NewRecordBase()
   at System.Data.DataTable.NewRecord(Int32 sourceRecord)
   at System.Data.DataRow.BeginEditInternal()
   at System.Data.DataRow.set_Item(DataColumn column, Object value)
   at CPITS.Data.OrdersRow.set_ExecutionPrice(Decimal value)

The strange thing is that this comes from the code generated by the framework (of course, I did not write Setter for the DataColumn).

Could you help me understand and fix this problem?

EDIT

Below is the code in which I set the value:

void ibclient_OrderStatus(object sender, OrderStatusEventArgs e)
{
    Data.OrdersRow drOrders = data.Orders.FindByOrderId(e.OrderId);

    if (drOrders != null)
    {
        drOrders.FilledQuantity = e.Filled;
        drOrders.ExecutionPrice = e.AverageFillPrice; //Sporadic Exception when setting a decimal value
    }
}
+4
3

RecordManager.NewRecordBase

internal int NewRecordBase()
{
  int num;
  if (this.freeRecordList.Count != 0)
  {
    num = this.freeRecordList[this.freeRecordList.Count - 1];
    this.freeRecordList.RemoveAt(this.freeRecordList.Count - 1);
  }
  else
  {
    if (this.lastFreeRecord >= this.recordCapacity)
      this.GrowRecordCapacity();
    num = this.lastFreeRecord;
    ++this.lastFreeRecord;
  }
  return num;
}

, , "index out of bounds":

num = this.freeRecordList[this.freeRecordList.Count - 1];

DataTable , , freeRecordList[..], this.freeRecordList.Count.

freeRecordList.Count while = > index out of bounds.

, , , concurrency ( , , !)

+3

, , , , , .

, .

+2

Method DataTable.GetErrors

Gets an array of DataRow objects containing errors.

+1
source

All Articles