none
Bug in .NET Framework -> System.Data.DataRow.set_Item(String columnName, Object value) RRS feed

  • Question

  •  

    Hello Everyone,

     

    I having the application which do frequent updated in the DataTable. Sometimes when the application running for long time, I got the following exception:

     
    ************** Exception Text **************
    System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
       at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
       at System.ThrowHelper.ThrowArgumentOutOfRangeException()
       at System.Data.DataTable.get_LiveIndexes()
       at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Int32 position, Boolean fireEvent, Exception& deferredException)
       at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean fireEvent)
       at System.Data.DataRow.EndEdit()
       at System.Data.DataRow.set_Item(DataColumn column, Object value)
       at System.Data.DataRow.set_Item(String columnName, Object value)
       at TradeCompanion.Form1.UpdateMarketData(FillMarketData mdata)
     
    It seems the bug with the Microsoft .NET Framework, Is there any patch available for this, from where I can download, or how can I fix it?
     
    Any help will be appreciated.
     
    Thanks,
    Rahul
     
     
    Monday, July 23, 2007 12:09 PM

All replies

  • How do you know its not a bug in your code? Post the code so people can determine what it is and possibly recreate it.
    Monday, July 23, 2007 1:23 PM
  • Ok I agreed, it can be bug in my code too, I did some research on this before posting it, here is one link on similar type of error where  it says microsoft conforms about the bug in .NET framework.

    http://www.kbalertz.com/kb_836874.aspx

     

     

    However you can see my code below

     

    Private Sub UpdateMarketData(ByVal mdata As TradingInterface.FillMarketData)

    SyncLock Me

    Dim drr() As DataRow = dsMarkeData.Tables(0).Select("Symbol = '" + mdata.Symbol + "'")

    If (drr.Length > 0) Then

    'drr(0)("BidPrice") = mdata.BidPrice

    drr(0)("OfferPrice") = mdata.OfferPrice

    drr(0)("TimeStamps") = DateTime.Now.ToString()

    Else

    Dim dr As DataRow = dsMarkeData.Tables(0).NewRow()

    dr("Symbol") = mdata.Symbol

    dr("BidPrice") = mdata.BidPrice

    dr("OfferPrice") = mdata.OfferPrice

    dr("TimeStamps") = DateTime.Now.ToString()

    dsMarkeData.Tables(0).Rows.Add(dr)

    End If

    End SyncLock

    End Sub

     

    The above method somewhere giving me the exception

    Monday, July 23, 2007 1:44 PM
  • Which call to the indexer generates the exception?  Can you verify that the DataTable contains a column with the name sent to the indexer?
    Monday, July 23, 2007 11:00 PM
  • Hi,

          I am not sure exactly which line is giving me the error.

    But it should be one of there three

     

    drr(0)("BidPrice") = mdata.BidPrice

    drr(0)("OfferPrice") = mdata.OfferPrice

    drr(0)("TimeStamps") = DateTime.Now.ToString()

     

    I am sure that these three columns are present in the DataTable. Another thing,  this exception is not very frequent, its coming in a interval of 4-5 hrs, when the application runs for longer time, most of the time, it works as per behaviour, which means columns are presebt in the datatable, it seems to me that the application runs for longer time, the datatable get corrupted or something.

     

    I am using the same dataset in many other places also, but every where I am only reading the values, not editing or deleting. Yesterday I got one more exception in my clients environment in the same methond.

     

    System.InvalidOperationException: DataTable internal index is corrupted: '5'.
       at System.Data.RBTree`1.RBInsert(Int32 root_id, Int32 x_id, Int32 position)
       at System.Data.RBTree`1.RBInsert(Int32 root_id, Int32 x_id, Int32 position)
       at System.Data.Index.RecordStateChanged(Int32 oldRecord, DataViewRowState oldOldState, DataViewRowState oldNewState, Int32 newRecord, DataViewRowState newOldState, DataViewRowState newNewState)
       at System.Data.DataTable.RecordStateChanged(Int32 record1, DataViewRowState oldState1, DataViewRowState newState1, Int32 record2, DataViewRowState oldState2, DataViewRowState newState2)
       at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Int32 position, Boolean fireEvent, Exception& deferredException)
       at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean fireEvent)
       at System.Data.DataRow.EndEdit()
       at System.Data.DataRow.set_Item(DataColumn column, Object value)
       at System.Data.DataRow.set_Item(String columnName, Object value)
       at TradeCompanion.Form1.UpdateMarketData(FillMarketData mdata)

     

    My customer is really pissed due to these exceptions in DataSets. How can I get rid of this?

     

    Thanks,

    Rahul

     

     

    Tuesday, July 24, 2007 5:34 AM
  • Not sure if you have access to a debugger (e.g. F10, F11, etc), but I found a 'potential' list of workarounds for your problem:

     

    http://connect.microsoft.com/VisualStudio/feedback/Workaround.aspx?FeedbackID=98279

    Tuesday, July 24, 2007 6:26 PM
  •  

    Thanks Eric, I will look into it, and see if it is possible fix that.
    Thursday, July 26, 2007 8:52 AM