Here are 4 reasons how “DataTable internal index is corrupted” happens.
1)Changing values during DataView.ListChanged event. This is not supported.
Look at the call stack and if you see DataView.OnListChanged and you are changing a DataRow/Set/Table, and then index corruption will likely happen (i.e. thrown
Short description of the problem: the internal indexes getting notified of the edits out-of-order.
Workaround - use the DataTable.RowChanged event instead of the DataView.ListChanged.
2)There is still an unfixed bug when merging data into an existing DataRow that starts in the Added or Deleted state and ends in the Modified row state.
DataAdapter.Fill, DataSet.Load, DataTable.Load when LoadOption.PreserveChanges.
DataSet.Merge, DataTable.Merge deleted rows.
DataSet.Merge (DataRow) for added rows.
Short description of the problem: The DataTable tells the DataView to “add” instead of “change”, resulting in index corruption.
The DataSet/DataTable and any connected objects are not thread safe.Make sure you lock all the appropriate objects.
4)When the DataColumn.DataType is a reference type and the values are being changed instead of being treated as read only.
Example: DataColumn.DataType is byte and the column sorted.If the values in the byte array are changed instead of assigning a new byte array to the DataRow, the internal index doesn’t know about the change and becomes corrupt.
This is data being changed without the internal index being notified.