none
Exception: DataTable internal index is corrupted: '5'. on ...

    Вопрос

  •  

        Hi, I have a problem with bindingsource component in framework 2.0.

    I have a combobox bound to a bindingsource which is also bound to a dataset with 2 related tables and a datagridview bound to the same bindingsource. What I want to do is : When the selectedindex property of my combobox changes, the corresponding cell value must be changed in the datagridview. But although the value in bindingsource changes, datagridview does not display the new value. That value is displayed after I move the mouse over that cell and make it invalidate its region manually.

    Another error I caught is the one that you can see as the subject of my post. I do not know why i have that message when I try to change the property of ((DataRowView)mybindingsource.Current)["MyProperty"] programmatically.

    I will be grateful if someone can help me.

     

    • Перемещено Val MazurModerator 4 сентября 2012 г. 19:51 (From:ADO.NET Managed Providers)
    2 марта 2006 г. 16:08

Все ответы

  • Post a code example for the internal index is corrupted issue, this sounds like a bug.

    Sorry I can't help you on the binding issue.

    6 марта 2006 г. 9:14
  • Hi Matt,

    I have the same problem.

    I have a typed dataset and sometimes, I don't know why, when I want to select some information in a DataTable and show (no Databinding) some information on my webpage I get this error.

    Here is the exact exception :

    StackTrace :
    Source: System.Data
    Methode: RBInsert
    Message: DataTable internal index is corrupted: '5'.
    StackTrace : 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.InitRecords(IFilter filter)
    at System.Data.Index..ctor(DataTable table, Int32[] ndexDesc, IndexField[] indexFields, DataViewRowState recordStates, IFilter rowFilter)
    at System.Data.Select.CreateIndex()
    at System.Data.Select.SelectRows()
    at System.Data.DataTable.Select(String filterExpression)
    at Composants_Publicite.Afficher()

    It can work for many days and then I suddenly get this exception.

    I can send you some code but I can't post it here due to security reason.

    Thx for your help.

    15 марта 2006 г. 21:48
  • I'll check with the devs to see if they've heard of this one yet.
    17 марта 2006 г. 5:08
  • We have a bug filed on this but we have not narrowed down a way to reproduce this yet.   Could you reply to me with some information on how you manipulate this DataTable?

    For example are you modifying this DataTable from multiple threads concurrently? 
    It is possible that this could corrupt it.  According to the devs:

    The internal index is corrupted "5" message typically gets thrown when 2 or more rows end with the same row id.

    This is a problem for DataTable because the row id should always be unique.

    So I theorize if 2 threads simultaneously add rows to the DataTable this could cause the corruption.

    18 марта 2006 г. 21:32
  • Yes It could be the problem.

    My DataSet is stored on the Application Cache and every user can potentialy access and, sometimes, modify the content of a row.

    But I had another exception telling that I cannot modify the same row at the same time. Now I modify it in order that the DataSet is now read only and I have no more exception on this DataSet.

    19 марта 2006 г. 17:27
  •  

    after I red this thread I'm sure it is a bug in .NET framwork 2.0. I discoverd this exception several times in different applications. but yet I was unable to reproduce it while debugging :-(

    .. and it could not be a threading problem, having two thread inserting data, because I do not user different threads on that DataSet.

    any news on it from MS ?

     

    6 апреля 2006 г. 12:25
  • We're still looking for a repro.  So if anyone out there has a repro please post it here.

    Also if you have some code that reproduces it but not consistently post this too.

    Anything that could help us figure out how to reproduce would be good, thanks for all your help thus far folks!

    6 апреля 2006 г. 16:57
  • Note someone forwarded one repro to me thus far and it turns out that this one was caused by multi-threaded access to the DataTable.

    So key thing for everyone to note.  If you modify a DataTable on multiple threads, you can corrupt the indexes on it and this is by design.  The DataTable is not designed to be thread safe for modifications for performance reasons.  So to resolve this you need to use the lock statement around all modifications to DataTable.

    Modifications include:

    1. Adding, deleting, modifying rows in DataTable.

    2. Selecting rows using Select method on DataTable (yes, this can modify the DataTable by creating a new index on it).

    3. Creating DataViews over a DataTable (same as #2, this can cause a new index to be created on DataTable).

    4. Modifying Sort property.

    I am sure there are some others I missed.  In general using the same DataTable on multiple threads is tricky business unless you restrict DataTable to100% read only operations (like enumerating rows and reading values).

    11 апреля 2006 г. 1:26
  • I am 100% sure, that this bug has nothing to do with multiple-thread. Our users ran into the bug several times a day. Now I implemented the following work-around:

    ' ------------------------------------------------------------------------------------------------

    dt.Clear()

    Me.Owner.DbConnector.FillDataAdapter(da, dt)

    <CurrentBindingContext>.SuspendBinding()

    Table.BeginLoadData()

    Table.DataSet.Merge(dt, False, MissingSchemaAction.Add)

    Table.EndLoadData()

    <CurrentBindingContext>.ResumeBinding()

    ' ------------------------------------------------------------------------------------------------

    I added the red-maked-code to the method where I do the .Reload of my DataSet. (The same Code is used after saving the Table.)

    On the side of the user-code I do not change anything. Just using NewRow and Rows.Add. - what caused the corrupted: '5' Error before. And now the error is gone.

    ' ------------------------------------------------------------------------------------------------

    Dim NewRow As DataRow = Me.Table.NewRow

    ...

    Me.Table.Rows.Add(NewRow)

     

     

     

    13 апреля 2006 г. 9:06
  • I am getting this same "data table internal index is corrupt '5'" error when trying to update a row using one of the table adapters I created with a data source in VS 2005.  This code has been working without problems for months.  The error occurs about 30% of the time.  Here is an example of the code I am using:

    DataRowView rv = (DataRowView)myBindinfSource.Current;

    myDataSource.myTableDataRow row = (myDataSource.myTableDataRow)rv.Row;

    row.ID = 12;

    int updated = mtTableTableAdapter.Update(row);

    myDataSource.AcceptChanges();

    Does anyone at least know of any work arounds?

    13 апреля 2006 г. 15:30
  • I think the problem you have is not caused while Update and AcceptChanges are executing. you should add a Table.Begin/EndLoadData to you code or add Suspend/Resumebinding during .Fill

    you can find 2 workarounds on the MS bug-report. the combination of both is workling in my applications.

    http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=ecc665a5-d71a-4e08-ac42-f3c6c5d758e0#Workarounds

    13 апреля 2006 г. 16:29
  • I have tried using the Begin/EndLoadData as well as the Suspend/ResumeBinding tricks to try to get this to work but this error keeps rearing its' ugly head...still only sometimes though.  I really wish I could find more information regarding why this could be happening.  I am not using threads at all.....
    19 апреля 2006 г. 19:45
  • I seem to be able to reproduce this fairly consistently. I'm handling the CurrentItemChanged event on the binding source and using that to detect changes to one column that need to be propogated to others. Whenever I set a value against a column using the binding source Current property to access the DataRowView I get this exception.

    I've tried all the work arounds, but none seem to work. It doesn't seem to matter which event I connect to from the binding source, they all seem to throw this exception if I try to change the underlying data.

    26 апреля 2006 г. 12:26
  • Could you post a repro so I can get this to the dev who owns the bug?

    Thanks!

    26 апреля 2006 г. 17:26
  •   

         To reproduce it :

    1) Load a datatable with a dataadapter

    2) modify a data and save it to the database "without" closing the form and then modify the data again and save to the database again

    3) That's all

     

       

    28 апреля 2006 г. 18:15
  • We found a consistent way to reproduce this:

    using Asp.Net:

    - use a DataTable and store it in the cache

    - Create a DataView on the table

    - Bind a control to the DataView (this step is not necessary I think)

    - stress test the web page, sending multiple http requests at the same time.

    Very soon the error will start to appear.

  • Yes, this goes back to my original theory.

    A DataTable is thread safe for read operations but not for write operations.

    So this means you can store a DataTable in the cache and extract it and use it in a read only fashion and it will work fine.

    However, creating a DataView on a DataTable is a write operation on a DataTable.  Most people don't know this, and its not very intuitive so I don't blame them for not knowing this.

    What happens when you create a DataView on a DataTable is the DataView will create an index on the DataTable and this index is stored in the DataTable.  The reason for this is performance, for example if you create a DataView saying "F1=1" as the criteria, this creates an internal index on the DataTable to locate this information.  Later on if you create another DataView with the same criteria, the index is reused, so this improves performance.   However the fact that these indexes are stored inside the DataTable means that these are write operations to the DataTable and thus they are not thread safe.

    So if you are creating random DataViews on the DataTable you are constantly creating new indexes.  If you are creating the same type of DataView over and over you are constantly reusing existing index.

    So unfortunately you need to serialize the creating of DataViews over the DataTable.

    You could do this for example to avoid the problem:

    lock(myDataTableFromCache)

    {

    dv = new DataView(myDataTableFromCache,...);

    }

    So lock using the DataTable as the locking object and lock when creating the DataView should solve the problem.

     

     

     

     

  • OK, I met this error as well but in bit different circumstances...

    I have 2 tables in my dataset (loaded from xml file).

    I have 2 DataGridViews which are bound to 2 BindingSources respectively.

    my user need to be able to move a line from DataGridView A to DataGridView B and back.

    In my code I create new row of Table B, fills it with values from line aa of DataGridView A, add the row to table B and delete the line aa from DataGridView A.

    When moving line from DataGridView B to DataGridView A I do the same just the in opposite direction.

    I get the error after doing several move like described on the same line.

    A->B, B->A, A->B and get the error on this line:

    Me.Ds.dtB.Rows.Add(NewRow)

    and the weirdest thing is that when I surround the code with "try catch" - I saw the error in a messagebox but the line did enter Table B and DataGridView B !!!!!!!!!!

    When tried to move it back to DataGridView A - I got the same error again but this time an empty row has been added to table A and DataGridView A.

     

    Hope this help a little and that a solution is on the way...

  • Sorry to burst your bubble on this, but I have a reproduction scenario on this which does not have anything to do with threading. It seems to have to do with expression field updating using the CHILD() expression function.

    I will post a code sample as soon as I can isolate one.

    Andy

    Another Item - if I use the lock statement to lock the row I'm operating on, then the code works fine. Are expression evaluations performed out of band on a different thread???

  • Awesome, if you can get me the repro code I can give it straight to the dev that wrote the DataSet and we can get this fixed.
  • To correct my prior statements, the lock keyword did NOT work reliability. However, as this is a sometimes works/sometimes doesn't problem, I would suspect a race condition.
  • Note as a follow up I talked to the DataSet gurus and they indicated that with .NET 2.0 creating DataView is now protected by internal locks so in theory there is no need to syncrhonized creating DataViews over a DataSet with .NET 2.0.

    Still looking for a repro for this one.  I put together some test code on my own to stress multi-threaded DataView creation and could not reproduce any failures.

  • Any ideas on a similar error ('13' instead of '5'):

    System.InvalidOperationException: DataTable internal index is corrupted: '13'.
    at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)
    at System.Data.Index.GetRows(Range range)
    at System.Data.Index.GetRows(Object[] values)
    at System.Data.DataRelation.GetChildRows(DataKey parentKey, DataKey childKey, DataRow parentRow, DataRowVersion version)
    at System.Data.DataRow.GetChildRows(DataRelation relation, DataRowVersion version)
    at System.Data.DataRow.GetChildRows(DataRelation relation)
    at Store24.Store24Lib.ScrubProductsTable(DataRelation relation, String exclCategories, String[] productExcludeArray) in C:\Documents and Settings\chrwil\My Documents\Visual Studio 2005\Projects\Store24.2\Store24.2\Store24.cs:line 1956 
     

    private static void ScrubProductsTable(DataRelation relation, string exclCategories, string[] productExcludeArray)
    {
        foreach (DataRow parentDataRow in relation.ParentTable.Rows)
        {
            bool allProdsDeleted = ScrubProductsTable(parentDataRow.GetChildRows(relation), exclCategories, productExcludeArray);
    
            if (allProdsDeleted)
            {
                parentDataRow.Delete();   // No children so kill parent
            }
        }
    }
    
    private static bool ScrubProductsTable(DataRow[] dataRows, string exclCategories, string[] productExcludeArray)
    {
        bool allProdsDeleted = true;   // Return value At least 1 row remains
    
        foreach (DataRow mDataRow in dataRows)
        {
    	if (exclCategories.Contains((string)mDataRow["sales_category_id"]) || 
    	    Array.BinarySearch(productExcludeArray, mDataRow["product_id"]) >= 0)
    	{
    	    mDataRow.Delete();
    	}
    	else
    	{
    	    allProdsDeleted = false;   // At least 1 child row remains so do not delete parent
    	}
        }
    
        return (allProdsDeleted);
    }
    
    
  • I think the problem was that the DataTable was in a DataSet that was in cache. Perhaps another user was doing the same thing with the same DataSet at the same time. I need to make a copy of the object before deleting rows from it.

     

    GarDavis

    2 июня 2006 г. 18:41
  • Yes this is very possible.  I know a few years ago I was working with a customer who was using DataSet as a cache of data and one thing we did to avoid issues was implement a "copy on write" scheme.  So you setup some code where if the caller wants to modify the DataSet they call a special function to get a copy and then modify the copy and when the modification is finished the writer copies over the older copy. 

    The writer "checks out" a copy, modifies the copy, then "checks in" the new copy.

    Readers always get a static copy since the assignment of a DataSet to a variable is atomic.  The only special case scenario you had to watch out for was multiple concurrent writers (we just used a global lock to handle this because writes were relatively rare).

    2 июня 2006 г. 20:28
  • We found that we received this exception due to side effects of BindingManagerBase.EndCurrentEdit that caused a second nested call to EndCurrentEdit OR SuspendBinding.  This was due to the way we save our data to the database in our UI and we were able to code around it.  The exception never occured in 1.1 of the framework however.
    23 июня 2006 г. 17:41
  • Any news about this issue?

    I've got the same problem with a multithreaded application. Unfortunately locking is no option because the app is performance critical. In my humble opinion it's a shame that such an essential data type is not working properly for months. This situation is typical for MS, this bug is apparent for months and nothing satisfying happened. You folk's should release the source code, surely somebody would fix this problem for you before you do.

    24 июля 2006 г. 15:51
  • I discoverd that this bug only appears if the Defaultview.Sort property has been set and a Column-Value wich belongs to .Sort will be changed. The Exception occured every 10-20 Row-Changes to a Col (included in .Sort).

    After I eleminated the Sort (now I load the records from SQL Server in order), the exception does not appear any more.

    Maybe this helps you to find the bug. more info needed, please dont hesitate contacting me.

     ' -- Code Segment --------------

    Private Sub FlexGrid_CellChanged(ByVal sender As Object, ByVal e As C1.Win.C1FlexGrid.RowColEventArgs)

    Dim Row As DataRow = Me.FindDataRow(e.Row)

    Dim ColName As String = Me.FlexGrid.Cols(e.Col).ColumnName

    Try

    If IsNothing(Me.FlexGrid(e.Row, e.Col)) Then

    Row(ColName) = System.Convert.DBNull

    Else

    Row(ColName) = Me.FlexGrid(e.Row, e.Col) <-- this change caused the error

    End If

    End If

    Catch ex As System.InvalidOperationException

    ' BUG in .NET framework

    <Reload DataSet From SQL> + continue

    End Try

    end sub

     

    25 июля 2006 г. 11:44
  • I got this error too and found a workaround for MY situation but I doubt that it will help anyone else. I'll post anyway though.

    This is NOT a threading issue in my case. I have a desktop C# application that has a tabbed form. On one of the tabs, there is a date field which defaults to today's date. It is databound to a field on a domain object, but it wasn't binding consistantly to the value, so I used the "Validated" eventHandler to manually set the value. This didn't work consistantly either though. So I changed it to use the "ValueChanged" eventHandler. This copies the value consistantly. However, I began getting this error when I tried replacing the domain object from XML after visiting this tab, whether or not I changed the value. (The ValueChanged handler is called on entry to the tab.) To get rid of this error, before changing the value in the domain object I compared the two values and did not replace them if there was no difference. Don't ask me why, but this worked. I can now change the value and it will change in the domain object, but for some reason, on the first entry into the tab, it screwed something up without the fix. Below is sample code:

    private void enteredDateDateTimePicker1_ValueChanged(object sender, EventArgs e)

    {

    //Manually set the date values

    if (sender == tDateTimePicker && !domainObject.tDate.Equals(tDateTimePicker.Value)) // I added the second condition to get rid of the error.

    {

    domainObject.tDate = tDateTimePicker.Value;

    }

    }

    Cheers,

    Nathan

    11 сентября 2006 г. 14:17
  • Note to everyone who responded to this thread: MANY THANKS!

    I finally got a repro over to the dev who owns this code and he is fixing the issue now.

    I'll post back once the fix is available.

    11 сентября 2006 г. 18:02
  • I've encountered the same problem in a project i'm currently working on.

    Has there been any progress on this issue as yet?

    Cheers

    21 сентября 2006 г. 6:04
  • Description of the Problem:

    I appear to have a similar situation:

    I have a table with several expression columns which contain information from parent tables.  After I delete a row from the table in the dataset using the code below:

    if (this.BindingSource.Current != null)

    {

    ((DataRowView)this.BindingSource.Current).Row.Delete();

    }

    And then I execute the following code:

    this.EndBindingSourceEdit(this.BindingSource);

    this.m_dsStaff.RejectChanges();

    The error, " DataTable internal index is corrupted: '5' " occurs on the line this.m_dsStaff.RejectChanges();

    Do you have any insights or a work around for this?

     

    Additional Info:

    The variable m_dsStaff references my dataset.  This dataset is the DataSource for the BindingSource.  The BindingSource is the DataSource for all of the other controls on the form, including a DataGridView.  The method EndBindingSourceEdit() is as follows:

    protected void EndBindingSourceEdit(BindingSource p_BindingSource)

    {

    if (p_BindingSource.Current != null)

    {

    if (p_BindingSource.Current is DataRowView)

    {

    if (((DataRowView)(p_BindingSource.Current)).IsEdit)

    {

    ((DataRowView)(p_BindingSource.Current)).EndEdit();

    }

    }

    }

    }

     

    21 сентября 2006 г. 18:10
  • I also have the same problem.

    Is there any known workaround?

    26 сентября 2006 г. 10:57
  • While we wait for the developer to complete the fix, could you please provide some detail as to what scenario the repro exposed as a defect? I imagine there are a number of scenarios that might result in this exception, some of which are valid, such as the case with performing unsynchronized write operations from concurrent threads. Does the repro have anything to do with a DataTable containing DataColumn expressions that reference parent/child relations? Thanks.

    28 сентября 2006 г. 13:43
  • Hi folks,

    I talked to the developer yesturday and got some more detailed information on the root cause of the corruption.  Let me detail the cause and this can help you avoid the problem until we have a fix.  Note the fix is a bit difficult and requires some rearchitecture of event handling so unfortunately it is not a trivial fix.

    In general, the issue is caused by user code in a DataView event handler that modifies the underlying DataTable.  According to the dev this is not supported (or we never intended for this to work), but I we have not found any mention of this in the documentation.

    More details from the dev:

    "Problem is the user is making a write operation during a DataView.ListChanged event; this is not supported in V1.0, V1.1 or V2.0.  This is not documented well; I’m still looking for the reference. The workaround is to listen to the DataTable.RowChanged event."

    So in general the workaround is to examine your code and look at code that is triggered by the DataView.ListChanged event closely.  See if you can mode this to DataTable.RowChanged event or see if you can avoid doing modifications to the DataTable in the DataView.ListChanged event.

    Matt

    28 сентября 2006 г. 16:24
  • From my experience I can tell you that the DataView.ListChanged Event could not be the 'only' reason for this bug. I'm not using DataView.ListChanged at all, but from time to time my useres run into the bug. Otherwise I can not rule out now that it could caused by events like BindingManager.CurrentChanged. I'm using that to handle sort of master/detail dependecies.

    Stefan

     

    29 сентября 2006 г. 7:00
  • I get this error when I've bound a DataTable to a DataGridView, and then I edit the value in the column that the DataGridView is being sorted by.  I never even go near the ListChanged Event.

    5 октября 2006 г. 6:59
  • I have managed to reproduce this problem without using the ListChanged events also.

    I have a form, with controls that are bound to a BindingSource.  The error is caused when I am adding a new record and I want to set a field that I dont have a control for, which I am doing by BindingSource.Current("FieldName") = value.  The error is then thrown on the Adapter.Update command.
    6 октября 2006 г. 8:24
  • I have the same problem as everyone else as described, I am modifying a column that's listed in the .Sort property.

    I have a DataGridView bound to a DataTable, and during updates to the table everything works fine until I sort by a particular column, and start modifying the values in the column.  After 10-15 or some odd number of field changes to that column, the whole program crashes and it won't even catch the exception.

    I don't listen for ListChanged, or RowChanged.  I don't write anything during those events.  If the ListChanged workaround is the case, the DataGridView is the one listening and modifying data.  How do we prevent the DGV from doing anything?
    11 октября 2006 г. 2:17
  • I removed DataGridView from the equation and manually set the DataTable.DefaultView.Sort property to a column that's being modified, and sure enough after a few updates to the column in the .Sort property:

    A first chance exception of type 'System.InvalidOperationException' occurred in System.Data.dll
    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()

    Code:

    Table.DefaultView.Sort = "ColumnBeingEdited";
    int i = 0;
    foreach (DataRow dr in Table.Rows)
    {
        dr.BeginEdit();
        dr["ColumnBeingEdited"] = ++i.ToString();
        dr.EndEdit();
    }

    I didn't even have to bind anything, but I did have to call the foreach() method via button click a couple times to finally corrupt it (the number of times seems to be random and based on the amount of rows in the table.)

    Hope this helps!
    11 октября 2006 г. 14:00
  • Ran this fairly simple code all day, no corruption, can you modify this code to make the problem reproduce?

    private string RandomString(int totalLength, Random rnd)
    {
     StringBuilder sb = new StringBuilder(totalLength);
     char ch = 'A';
     
     for (int i=1; i<=totalLength; i++)
     {
      sb.Append(ch+((char)rnd.Next(0,25)));
     }
     return sb.ToString();
    }
    static DataTable Table = null;
    static Random rnd = new Random(Environment.TickCount);
    private void button14_Click(object sender, EventArgs e)
    {
     if (null == Table || rnd.Next(1,10) < 5)
     {
      Table = new DataTable("table1");
      Table.Columns.Add("f1",typeof(string));
      int stringLength = rnd.Next(5,100);
      int rowCount = rnd.Next(10,1000);
      
      System.Diagnostics.Debug.WriteLine("stringLength=" + stringLength + " rowCount=" + rowCount);
      
      for (int i=1; i<=rowCount; i++)
      {
       DataRow r = Table.NewRow();
       r["f1"] = RandomString(stringLength, rnd);
       Table.Rows.Add(r);
      }
      
      Table.DefaultView.Sort = "f1";
     }
     int rowValue = 0;
     foreach (DataRow dr in Table.Rows)
     {
      dr.BeginEdit();
      dr["f1"] = (++rowValue).ToString();
      dr.EndEdit();
     }
     System.Diagnostics.Debug.WriteLine("Done!");
     
    }

    12 октября 2006 г. 16:07
  • Argh!  I had it reproduced with simple code and now I can't do *anything* to reproduce it, only in very rare circumstances.  Back to the drawing board.
    13 октября 2006 г. 18:33
  • Alright, now I can easily reproduce it 100% of the time without threads or binding (sorry to paste this much code):

    /* Note, when you remove the .Sort, you won't get the corruption. */

            public static DataTable Table;
            public System.Threading.Timer ChangeColumns;
            public Random random;
            public System.Windows.Forms.Timer timer;

            public Form1()
            {
                InitializeComponent();
                random = new Random();
                Table = new DataTable();
                DataColumnCollection cols = Table.Columns;
                cols.Add("Column1", typeof(String));
                cols.Add("Column2", typeof(String));
                cols.Add("Edited", typeof(CellObject));

                for (int i = 0; i < 1000; i++)
                    AddRandRow();

                Table.DefaultView.Sort = "Edited";
                //dataGridView1.DataSource = Table;

                timer = new System.Windows.Forms.Timer();
                timer.Interval = 500;
                timer.Tick += new EventHandler(timer_Tick);
                timer.Start();
            }

            void timer_Tick(object sender, EventArgs e)
            {
                EditColumns();
            }

            void EditColumns()
            {
                foreach (DataRow dr in Table.Rows)
                {
                    dr.BeginEdit();
                    ((CellObject)dr["Edited"]).test1 = random.Next(0, 1000);
                    ((CellObject)dr["Edited"]).test2 = random.Next(0, 1000);
                    dr.EndEdit();
                }
            }

            public void AddRandRow()
            {
                DataRow newRow = Table.NewRow();
                newRow.BeginEdit();
                newRow["Column1"] = random.Next(0, 500);
                newRow["Column2"] = random.Next(0, 500);
                CellObject c = new CellObject(random.Next(0, 500), random.Next(0, 500));
                newRow["Edited"] = c;
                newRow.EndEdit();
                Table.Rows.Add(newRow);
            }
        }

        public class CellObject
        {
            public int test1;
            public int test2;

            public CellObject(int a, int b)
            {
                test1 = a;
                test2 = b;
            }

            public override string ToString()
            {
                return test1.ToString();
            }
        }


    13 октября 2006 г. 19:11
  • Cool, I can reproduce using the above code, I'll check with the dev to verify if this falls under the same scenario or not.
    13 октября 2006 г. 20:28
  • Hello Matt Neerincx:

    Has any news ?I Have meet this problem!

     

    http://www.cnblogs.com/hjf1223/archive/2006/10/17/531416.html

    19 октября 2006 г. 8:26
  • I got this error in diffrent Situation

     

    1.I have a datatable in client side(Winform) ,i am mergeing it with a datatable which is from data access layer and binding it to datagrid for display

    as shown below

    dtPhoto.Merge(Objphotos.Get_PhotoInfo(strWarrant_Number), True)

    dtPhoto.AcceptChanges()

    Me.DGPhotoView.DataSource = dtPhoto

    2.From the datagridview user can select any row of data and delete it  and rebuinding i to grid view.

    dtPhoto.Rows(RowNumber).Delete()

    dtPhoto.AcceptChanges()

    Me.DGPhotoView.DataSource = dtPhoto

    3. New row is added to same datatable as below

    Dim Photodetailsrow As DataRow

    Photodetailsrow = dtPhoto.NewRow()

    Photodetailsrow.BeginEdit()

    Photodetailsrow("Photo_Date") = StrPTDate

    Photodetailsrow("Photo_Time") = StrPtakenTime

    Photodetailsrow("Photo_View") = strPTView

    Photodetailsrow("File_Path") = strFilePath

    Photodetailsrow.EndEdit()

    dtPhoto.Rows.Add(Photodetailsrow)<---Line of code throws Exception: DataTable internal index is corrupted: '5'. on ...

    dtPhoto.AcceptChanges()

    Return dtPhoto

    Can any one help me to fix this please ,

     

     

    27 октября 2006 г. 19:31
  • Is there any progress on this matter?

    Is there going to be a fix avalible soon?

    31 октября 2006 г. 10:24
  • No progress yet, no news on a fix for this either.  I'm working with an ISV to push for a fix.
    31 октября 2006 г. 18:53
  • thanks,

    while we wait for a fix, is there a good workaround for this bug?

    I've tried the beginloaddata - endloaddata workaround, did not work for me.

    1 ноября 2006 г. 2:07
  • Matt,

    I am getting this error too.  Is there anything more you can tell us so we can try to workaround this problem?  None of the workarounds mentioned so far have any effect.

    If we could at least understand the detailed conditions/scenarios that trigger this error, it would help us come up with new ways to try to work around it.

    Thanks.

    2 ноября 2006 г. 22:34
  • The three possible root causes thus far are:

    1. Multi-threaded modification of a DataSet/DataView/DataTable.  Most customers indicated that they were not doing this.

    2. Modification of DataSet/DataView/DataTable inside a ListChanged event handler.

    3. Modification of a DataSet/DataView/DataTable that contains a custom type that is not defined as serializable.  For example suppose you have a DataTable with column of type MyCustomClass and this class is not defined as serializable.

    Here is current list of workarounds:

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

    2 ноября 2006 г. 23:50
  • Matt,

    I turned CellObject into a Serializable object and I still receive the same error.  Were you able to fix the custom class corruption by making it serializable and if so, how did you do it?
    7 ноября 2006 г. 15:26
  • Matt

     Mine is a web application which has a datagrid (about 20000rows) throws up index corrupted error even with concurrency of just 2 users

     I modified the code such a way that datatable.copy() is done and a view is created but still problem persists, is there any hotfix?

    dataTable = GetProductsData(dataTable)

    Dim dtCopyTable As DataTable = dataTable.Copy

    dtCopyTable.DefaultView.Sort = hdnSortExpr.Value  'This is a hidden control which contains sort expression

    dgSims.DataSource = dtCopyTable.DefaultView   

    hdnSort.Value = "0"

    dgSims.DataBind()

     

     

    Siva

     

    11 ноября 2006 г. 10:35
  • I've the same error. My application is a smart client which connects throug a webservice to dynamics ax. The Data from the Webservice comes as dataset and is merged to a local dataset. This is done without threading. Getting new data and inserting data (via merge) is allright, but sending changes of the local dataset and merging the returned data corrupts the index.

    I hope to get a fix soon :)

    15 ноября 2006 г. 8:39
  • Hi Matt!

    Is there any news on this topic.

    /Anders

    15 ноября 2006 г. 15:10
  • I just received this very, very serious Exception... and I see that is has not been fixed over the course of many months.

    This bug or bug complex apparently means that I cannot deliver a reliable Windows Forms application - one that does not crash.

    Please... when is it going to be fixed?

     

    System.InvalidOperationException was unhandled by user code
      Message="DataTable internal index is corrupted: '5'."
      Source="System.Data"
      StackTrace:
           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.DataTable.RejectChanges()
           at System.Data.DataSet.RejectChanges()
           at Extensive.Subscription.Views.Wizard.SubscriptionViewPresenter.SaveSubscriptionInfo(SubscriptionInfoDataSet theDataSet) in E:\r\extensive-dev\trunk\technical\app\RLS\RLS-SCSF\Source\Subscription\Subscription\Views\Wizard\SubscriptionViewPresenter.cs:line 141
           at Extensive.Subscription.Views.Wizard.SubscriptionView.paymentIntroWizardPage_BeforePageDisplayed(Object sender, WizardCancelPageChangeEventArgs e) in E:\r\extensive-dev\trunk\technical\app\RLS\RLS-SCSF\Source\Subscription\Subscription\Views\Wizard\SubscriptionView.cs:line 752
           at DevComponents.DotNetBar.WizardPage.OnBeforePageDisplayed(WizardCancelPageChangeEventArgs e)
           at DevComponents.DotNetBar.WizardPage.0B0(WizardCancelPageChangeEventArgs 6H5)
           at DevComponents.DotNetBar.Wizard.0BR(WizardPage 6HT, eWizardPageChangeSource 6HU)
           at DevComponents.DotNetBar.Wizard.NavigateNext()
           at DevComponents.DotNetBar.Wizard.0BK(Object 6HJ, EventArgs 6HK)
           at System.Windows.Forms.Control.OnClick(EventArgs e)
           at System.Windows.Forms.Button.OnClick(EventArgs e)
           at System.Windows.Forms.Button.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    18 ноября 2006 г. 22:24
  •  Matt Neerincx wrote:

    The three possible root causes thus far are:

    1. Multi-threaded modification of a DataSet/DataView/DataTable.  Most customers indicated that they were not doing this.

    2. Modification of DataSet/DataView/DataTable inside a ListChanged event handler.

    3. Modification of a DataSet/DataView/DataTable that contains a custom type that is not defined as serializable.  For example suppose you have a DataTable with column of type MyCustomClass and this class is not defined as serializable.

    Here is current list of workarounds:

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

    Hi Matt!

    I've got same problem on a Windows app. without using multiple threads. VB.Net.

    Is there any progress in solving the "index is corrupted:'5'" Error?

    Regards.

    Anders

    21 ноября 2006 г. 10:54
  • Anyone with a solution ???
    Non of the workarounds works for me!!!   
    30 ноября 2006 г. 14:21
  • For your information, my complete error message is

    Exception:
     System.InvalidOperationException: Der interne DataTable-Index ist beschädigt: '5'.

       bei System.Data.DataTable.RestoreIndexEvents(Boolean forceReset)

       bei System.Data.Merger.MergeTable(DataTable src, DataTable dst)

       bei System.Data.Merger.MergeTableData(DataTable src)

       bei System.Data.Merger.MergeDataSet(DataSet source)

       bei System.Data.DataSet.Merge(DataSet dataSet, Boolean preserveChanges, MissingSchemaAction missingSchemaAction)

     

    What I do (without threading) is that I call GetChanges of a Dataset and sent this data to a webservice. This webservice returns the same dataset (with some changes) to the caller. The retrieved DataSet is merged to the originally one.

    3 декабря 2006 г. 23:15
  • No news yet on a fix, sorry I have no good news yet.
    4 декабря 2006 г. 17:56
  • Hello Matt,

    i have some new informations for you, because I solved my problem. Two posts up you can read what I did. In short I have a smart client which sends data through a webservice.

    I got it to work with using RejectChanges!

    a) The Smartclients sends a dataset (with changes in e.g. one row) to the webservice. (with .GetChanges)

    b) The webservice processes the dataset and althoug changes in this row. He sends back the dataset

    c) The Smartclient calls RejectChanges on his local data, and then merges the data from the webservice

    ----

    Some more news. I tried an extra project to send and load the data to my webservice. I couldn't reproduce the bug in this new project. So my webservice should be ok and the problem is with merging the data on the local side, maybe because there are databindings active.

    4 декабря 2006 г. 22:19
  • Hi,

    what's up? Why does it take so long to fix this bug? I can't understand that. Can you reproduce it? What do you need? We can help you, but please, make something going on.....

    By the way, one more Exception of that type:

     System.InvalidOperationException: Der interne DataTable-Index ist beschädigt: '5'.
       bei System.Data.RBTree`1.RBInsert(Int32 root_id, Int32 x_id, Int32 position)
       bei System.Data.RBTree`1.RBInsert(Int32 root_id, Int32 x_id, Int32 position)
       bei System.Data.Index.InsertRecord(Int32 record, Boolean fireEvent)
       bei System.Data.Index.ApplyChangeAction(Int32 record, Int32 action)
       bei System.Data.Index.RecordStateChanged(Int32 oldRecord, DataViewRowState oldOldState, DataViewRowState oldNewState, Int32 newRecord, DataViewRowState newOldState, DataViewRowState newNewState)
       bei System.Data.DataTable.RecordStateChanged(Int32 record1, DataViewRowState oldState1, DataViewRowState newState1, Int32 record2, DataViewRowState oldState2, DataViewRowState newState2)
       bei System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Int32 position, Boolean fireEvent, Exception& deferredException)
       bei System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean fireEvent)
       bei System.Data.DataTable.RejectChanges()
       bei System.Data.DataSet.RejectChanges()
    22 декабря 2006 г. 13:07
  • Dear Matt,
    I am a developer which is part of team working on project implemented by C# and .NET 2 (recently also .NET 3).

    We are having problem with DataTable throwing exception "Internal index is corrupt '5'" sometimes. It does not happen consistnently, but it happen in certen places.

    I follow the msdn forum thread about this exception and I saw you post a solution.

    It is not exactly clear to me and I hope you can explain it in more details.
    Specificly, you said that one should not write to the table on DataView.ListChanged event handler, but in .NET 2 you add the great class BindingSource, which we use heavily in our project, and we use BindingSource's event also. Also we notice that when you bind a DataTable to a BindingSource it actualy use the default DataView of that table, also when you set the Filter property of the BindingSource it set the Filter property of the default view.
    Any way, does the BindingSource class event use DataView events internally and so I should not change the DataTable using BindingSource events?

    Thank you very much,
    Ido Ran.

    28 декабря 2006 г. 7:13
  • If it's helpful to anybody out there, I present the following example...

    I'm updating a DataTable that's a member of a typed DataSet on a row-basis (i.e. an update message comes into my app, I find the row, and apply the update to the row).  I was having the same problem, but I found that calling .BeginEdit() and .EndEdit() on the row solves it for me.  In addition, I have a SyncLock on the DataSet, and wrap the update in the DataSet's .BeginLoadData() and .EndLoadData methods.  Here's the code I'm talking about (it's kinda sloppy, but whatever, it works):

        SyncLock DsConsole1.StatusMain
            Try
                DsConsole1.StatusMain.BeginLoadData()
                Using oRow As DSConsole.StatusMainRow = _
                    DsConsole1.StatusMain.FindByObjectName(ObjectName)
                        With oRow                  
                            .BeginEdit()
                            .Status = Status
                            .FailCount = FailCount
                            .LastUpdate = EventTime
                            .EndEdit()
                        End With
                End Using
                DsConsole1.StatusMain.EndLoadData()
                Catch ex As Exception
                    'Logging happens here
            End Try
        End SyncLock


    I'm not sure if the SyncLocks or the .BeginLoadData() or .EndLoadData() are necessary or not -- they may not be... I put them in there before I remembered .BeginEdit() and .EndEdit(), but it works, and I'm getting close to my deadline, so at this point, I'm not willing to tempt fate by tinkering with it any more. 

    I haven't read the entirety of this thread, so if this is redundant info I apologize, but I hope this may help someone.  Happy programming!
    29 декабря 2006 г. 1:44
  • I was running into the same issue and found this thread looking for answers.  FWIW, I was able to get the problem to go away by removing the calls to DataRow.BeginEdit() and DataRow.EndEdit() which I had wrapped around my data updates.

    I'm not sure what the side effects of removing these calls will ultimately be, but since I'm using "raw" data rows (e.g. no constraints or validation) I'm hoping that there won't be any.  Still looking forward to a full resolution/explanation.

    16 января 2007 г. 19:43
  • Hi folks,

    Another update.  I realize I have not been very responsive here but there has not been much news over December on this issue.

    I found a customer a few weeks ago that is pushing for a QFE for this issue so we are getting some traction on getting this fixed now, the dev is working on a fix.  So hopefully soon we should have a fix for this available and when this happens I will post back with the details.  I've provided the dev with all of the repros you guys have posted over the past few months for testing out the fix.

    Matt

    16 января 2007 г. 21:54
  • Hi Matt, our software group is currently experiencing the same issue.

    Looking forward to a fix!!!
    19 января 2007 г. 19:16
  • Any word on a fix?
    None of the other solutions have worked for me.
    8 февраля 2007 г. 21:44
  • Hi Guys...

    I just feel we're left alone on this matter...

    I'm getting the "DataTable internal index is corrupted: '5'" exception when trying to apply changes to a datatable by doing Form.Validate(), BindingSource.EndEdit(). When execution gets to the EndEdit() method the exception is raised, sometimes.

    My case is a WinForm with a datagridview bound to a binding source with a typed datatable as the datasource. The lower area of the form has textboxes and comboboxes which allows for data entry. They are also bound to the BindingSource object.

    When I add a new record using bindingSource.AddNew() method, fill it with some data using the form, and immediatly click on the save button (which calls the methods described above) everything is fine. The record is in the db.

    If instead I want to create two or more new records, things get screwed up. there is a case when i add two records and just after editing the last field for the last new record, i click on save. I do Form.Validate() and when i call the BondingSource.EndEdit() method to apply changes to the datatable, I get the exception DataTable internal index is corrupted: '5'. this behaviour doesn't happen if the user navigates through the datagridview after adding the last records.

    Pier

     

    10 февраля 2007 г. 9:23
  • Hi Matt,

    just to update the list of possible reasons.
    I use a multithreaded application and get a "Der interne DataTable-Index ist beschädigt: '13'." exception:

    "   bei System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)
       bei System.Data.Index.GetRows(Range range)
       bei System.Data.Index.GetRows(Object[] values)
       bei System.Data.DataRelation.GetChildRows(DataKey parentKey, DataKey childKey, DataRow parentRow, DataRowVersion version)
       bei System.Data.DataRow.GetChildRows(DataRelation relation, DataRowVersion version)
       bei System.Data.DataRow.GetChildRows(String relationName)
       bei PubChemMassSearcher.Form1.bgw_statistics_DoWork(Object sender, DoWorkEventArgs e) in C:\\Dokumente und Einstellungen\\jahu\\Eigene Dateien\\Visual Studio 2005\\Projects\\DB_Tools.root\\xxx\\Form1.cs:Zeile 707.
       bei System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
       bei System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)"

    I want to access the childrows using GetChildRows(). Programming my application with one BackGroundWorker anything goes well. However, introducing multiple BackGroundWorkers to read in the DataSet this exception is thrown. Any of this BackGroundWorker trys to get a List of ChildRows according to a given row index in the parent data table.

    Any help is appreciated!

    with kind regards
        Jan


    11 февраля 2007 г. 22:02
  • Yes I have not forgotten about this thread.  I just emailed the PM to get a status update, he should post back soon.
    14 февраля 2007 г. 6:31
  • Any updates? I'm having a similar problem.

    Thanks!

    1 марта 2007 г. 23:49
  • Ok, we finally have a fix for this issue.  Sorry for the delay on this.

    You can call product support and get the fix for free (there is no charge to call and get a fix).

    Call Microsoft Product Support and ask for fix for KB 932491.

    Thanks to everyone for sending me repros for this, it helped when we did the fix to ensure we fixed the problem!

     

     

    2 марта 2007 г. 4:00
  •  

        No fix with the code yyou've given exists in Microsoft->Product Support->Knowlede Base and I also waited on the phone for 15 min, without any answer or result. If calling and getting the fix is free of charge, why don't you just give a link to download site?

    2 марта 2007 г. 7:51
  • There is no download site for this fix and the KB is not public yet.  This is a hotfix, we don't normally have a download site for a hotfix, you have to call support and they will get it for you.  Not sure exactly why we do things this way, but keep calling support and tell them you want the fix and they should be able to fetch it internally (I verified this much).

     

    2 марта 2007 г. 8:22
  • MSDN and the technical deparment can't find this given hotfix number???
    2 марта 2007 г. 11:33
  •  

     Yes, they can not find it :)

    2 марта 2007 г. 13:03
  • Hello,

    the first who gets it, could just post a link or a email address for requests. I'm from Italy and it could be a while for Ms Italia to actually distribute the hot fix.

    Pier

     

    2 марта 2007 г. 17:39
  • Tell support folks to search http://hotfix web site using KB number 932491 or they can search for fix name vsuqfe4769. It's available internally I already checked this.
    2 марта 2007 г. 17:54
  • I called 1-800-936-3500 picked developer support (option 3).

    Picked option 1 for hotfix.

    I got the support person and said I wanted hotfix 932491.  They said to me the fix did not exist. Doh!  Oh the irony.

    So I said "Could you check the hotfix server for this fix I was told by someone at Microsoft the fix was available but the KB is not public yet."

    Then the person checked the hotfix server and found that the fix was available and said they would transfer me to developer support so I could get the fix.

    Now I am on hold waiting for developer support, I will post back when I have more info.

    2 марта 2007 г. 18:03
  • Update to my saga.

    I called 1-800-936-3500 picked developer support (option 3).

    Picked option 1 for hotfix.

    I got the support person and said I wanted hotfix 932491.  They said to me the fix did not exist. Doh!  Oh the irony.

    So I said "Could you check the hotfix server for this fix I was told by someone at Microsoft the fix was available but the KB is not public yet."

    Then the person checked the hotfix server and found that the fix was available and said they would transfer me to developer support so I could get the fix.

    Now I am on hold waiting for developer support.  Then they took me off hold and said what version of SQL Server did I want the fix for (which was strange) so I said I wanted the fix for 32-bit SQL Server 2005 and .NET Framework 2.0.  This seemed to make them happy a bit and then they put me on hold again.  Took me off hold in 30 seconds and said my case number was SRX 070302 601587.  Then put me back on hold.

    So tell the support person you want the same hotfix that the guy for case #SRX070302601587 got, that should save some time as they put notes in the case usually explaining what happened.  I'm back on hold again, thank goodness for speakerphone so I can get some work done.

    2 марта 2007 г. 18:17
  • Ok, to get the fix:

     

    Call 1-800-936-3500 and choose:

    1. for support

    3. for developer support.

    1. for hotfix.

    Once you get someone on the line tell them you want the fix for KB 932491.  Be sure to tell them that the KB is not public yet but the hotfix is available.  Tell them that a Microsoft developer called into support and created case #SRX070302601587 and that the case notes for this case should have the details on how to get the fix.

    2 марта 2007 г. 21:31
  • I called MS support in germany and received the patch the same day !

    stefan

    3 марта 2007 г. 9:23
  • Kannst mit den mal schicken. Oder sage wo anrufen und ob man da einen Support Vertrag braucht. Ich find die richtige Nummer nicht.
    4 марта 2007 г. 12:01
  • Kannst mit den mal schicken. Oder sage wo anrufen und ob man da einen Support Vertrag braucht. Ich find die richtige Nummer nicht.

    Andreas(AT)Rudischhauser.de

    4 марта 2007 г. 12:01
  • einfach bei der Geschäftskundenbetreuung anrufen ... klappt problemlos.

    http://support.microsoft.com/contactus/?ws=support

    Privatkundenbetreuung
    Tel.: 01805 / 67 22 55*
    Fax: 01805 / 25 11 91*
    E-Mail: kunden@microsoft.com

    Geschäftskundenbetreuung
    Tel.: 01805 / 67 23 30*
    Fax: 01805 / 22 95 54*
    E-Mail: btob@microsoft.com

    Partnerbetreuung
    Tel.: 01805 / 30 25 25*
    Fax: 01805 / 30 25 26*
    E-Mail: 4partner@microsoft.com

     

    4 марта 2007 г. 16:42
  • Hello,

    I have manage to get the QFE 932491  from Microsoft Support after 3 days.

    I am sorry to say that I am still having InvalidOperationException with "Internal Index is curropt 5" after applying the fix.

    I have checked that some of the files were replaced by the fixed files. I also watch with Reflector on the fixed files and I notice the use of ReaderWriterLock in DataSet, DataTable and other classes in System.Data.

    The thing is in my application I belive the curropting of indeces occurs in a single thread.

    Are there any debug files or something I can do to get logs of what is happening during the executing of my application so I can deliver those to Microsoft for analysis?

     

    Thank you,

    Ido.

    9 марта 2007 г. 9:26
  • Post a code sample if possible and we'll take a look.
    12 марта 2007 г. 5:08
  • Dear Matt,

    We are trying to repreduce the excpetion in a project seperate from out large project.

    I hope we will be able to do it soon and we will post the code as soon as possible.

    I watch the code of the BCL wtih Reflector and I saw there is a log component (BID) in almost each method in the framework. Is it possible to capture that log and send it to you. I am asking this because inside our system we are able to repreduce the problem almost consistently.

     

    Thank you for your help,

    Ido.

    15 марта 2007 г. 19:33
  • Yes, you can try this.  Here is a good article that explains how to enable the tracing ->

    http://msdn2.microsoft.com/en-us/library/aa964124.aspx

    15 марта 2007 г. 20:14
  • Hi,

    I am just wondering what the test conditions are for the bug fix that have been released... does it only address situations where this error occurs under multithreaded access?  I get this exception randomly in a single-threaded application that has multiple C1TrueDBGrids bound to the same datatable.  I am not able to reproduce the error on my development machine.  Also, the error seems to occur at different spots in the program.  Sometimes it occurs within the C1 grid itself.  (See below.)

    We haven't applied the KB yet.

    Thanks.

    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.RBTree`1.Insert(K item)
       at System.Data.Index.InitRecords(IFilter filter)
       at System.Data.Index..ctor(DataTable table, Int32[] ndexDesc, IndexField[] indexFields, DataViewRowState recordStates, IFilter rowFilter)
       at System.Data.DataTable.GetIndex(IndexField[] indexDesc, DataViewRowState recordStates, IFilter rowFilter)
       at System.Data.DataView.UpdateIndex(Boolean force, Boolean fireEvent)
       at System.Data.DataView.UpdateIndex(Boolean force)
       at System.Data.DataView.SetIndex2(String newSort, DataViewRowState newRowStates, DataExpression newRowFilter, Boolean fireEvent)
       at System.Data.DataView.SetIndex(String newSort, DataViewRowState newRowStates, DataExpression newRowFilter)
       at System.Data.DataView.set_Sort(String value)
       at System.Data.DataView.System.ComponentModel.IBindingListView.ApplySort(ListSortDescriptionCollection sorts)
       at C1.Win.C1TrueDBGrid.BaseGrid.Frame.a(ListSortDescriptionCollection A_0)
       at a0.m(Int32 A_0)
       at C1.Win.C1TrueDBGrid.BaseGrid.View.OnClick(Point p)
       at C1.Win.C1TrueDBGrid.Split.OnClick(Point p)
       at cc.b(Point A_0)
       at C1.Win.C1TrueDBGrid.BaseGrid.Frame.doClick(EventArgs e)
       at C1.Win.C1TrueDBGrid.C1TrueDBGrid.doClick(EventArgs e)
       at C1.Win.C1TrueDBGrid.BaseGrid.Frame.OnClick(EventArgs e)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at C1.Win.C1TrueDBGrid.C1TrueDBGrid.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

     

    15 марта 2007 г. 22:14
  • Hi Matt,

    Thank you for the information about BID log.

    I will try to turn it on and gather the information.

    Can you direct me to what is the most important thing to collect and how should I send the logs once I will collect them?

     

    Thank you,

    Ido.

    17 марта 2007 г. 16:46
  • I'm sorry to say that I have also obtained the fix and still have the problem.

    I happened to find this thread earlier in the week when I first encountered the problem.  I called support and got the fix - but it didn't work.  I'm still getting: DataTable internal index is corrupted: '5' when I try to change a value in one particular datagridview in my application.  The other datagridviews seem to work just fine.  8 of the 9 datagridviews in my application are bound to binding sources, including the one giving me the problem.  There is only one thread in my application at the time.

    At this point I'm able to reproduce the problem very reliably.  I'd be happy to send you my entire project offline if it'll help.

    Mike

    17 марта 2007 г. 21:49
  • Dear Matt,

    I have collect the log of BID interface when the exception occur.

    Can you pelase send me you email address to ido.ran@gmail.com so I could send you the log.

    I do not wish to publish the log on this forum.

     

    Thank you,

    Ido.

    27 марта 2007 г. 17:43
  • Dear Matt,

    I think we have found the reason for "Internal Index is curropted 5" exception in our system.

    We are using DataSet and BindingSources on this DataSet.

    We are also registering for BindingSource's CurrentChanged event to detect that the user select a different record in a grid.

    Inside the handler of CurrentChanged we are calling AcceptChanges for some of the DataRows in the DataTables.

    Now, when we are binding a DataTable to BindingSource the BindingSource actually use the DefaultView of that table and then the BindingSource is registered to the View's ListChanged event to raise its own CurrentChanged event.

    I have looked at the call stack to verify this.

    As you wrote in previous post, when listening to DataView's ListChanged event and changing the underlying DataTable index currption may occur.

     

    Do you have any idea how can I deffer the action on the DataRow to later time.

    Something like using SendMessage or PostMessage in Win32 applications to deffer the action for the next message pump cycle?

     

    Thank you,

    Ido.

    29 марта 2007 г. 14:02
  • I also have a partial resolution to my problem.  It seems to be related to the C1TrueDBGrid.  Calling C1TrueDBGrid.UpdateData in the C1TrueDBGrid.Leave event seems to resolve the problem.  I have also noticed a case where the grid was not updating changes to the underlying dataset immediately on losing focus.
    29 марта 2007 г. 14:26
  • Yes I did something like this with an application I wrote a few years ago (I was creating records on a background thread and pumping them to UI thread).

     

    I did something simple like this ->

     

    private MethodInvoker miDoOnUI = null;

    private void DoSomethingOnUIThread()
      {
         // Add code here...
      }
    public void SomeFunction()
    {
     if ( null == miDoOnUI ) miDoOnUI = new MethodInvoker( this.DoSomethingOnUIThread );
     this.BeginInvoke( miDoAsync ); // This works if SomeFunction is a method of some System.Windows.Forms.Form derived class...
    }

    29 марта 2007 г. 17:51
  • Dear Matt,

    Thanks for the sample.

    My case is a little different because the update of the data occurs on the UI thread, so the CurrentChanged event handler is also executing on the UI thread.

    I thnk I have managed to deffer the update of DataTable and still keep it on the UI thread by using SynchronizationContext.Post method.

    Because I am running a Windows Forms application my SynchronizationContext.Current will return an instance of WindowsFormsSynchornizationContext. I have read the code using Reflector and did some testing and Post method of WindowsFormsSynchornizationContext uses PostMessage Windows API. This way I can deffer the update of the DataTable to the next windows message pump cycle.

    After making that change I did the actions which usually causing "Internal Index is curroped 5" excpetion and I was not able to repreduce the problem.

    Next week I will report again and tell you if it really help.

     

    Ido Ran.

    30 марта 2007 г. 9:05
  • I got this exception too,

    i think, the corruption takes place earlier before the exception occurres, only the next usage of the index throws the exception, but not the action that corrupts the index.

    Why does MS not check the index after each (wrong) modification, so it would be verry easy to find the code that corrupts it?

     

    My question is, how can i refresh or rebuild the index, so that it is no longer corrupted?

     

    (As i have seen, a lot of users working with TrueDBGrid, this has a wrong list changed handler, that does not work correct after clearing a table an reload it with new data)

     

    Can we have hope for a correct solution of this problem by MS?

     

    Tnx

     

    Roman

     

    2 апреля 2007 г. 11:37
  • OK, for what it's worth, I've encountered this problem as well. I have nailed the source of the problem down to the index that is attached to a DataGridView control within my app.

     

    The only way I found to sort out the problem was to force the DataGridView to rebuild its index. I did this by executing a MoveLast() followed immediately by a MoveFirst() when I'd finished adding new rows to the list.

     

    I know it's not particularly elegant but it worked for me.

    12 апреля 2007 г. 6:29
  • I used to get this error in my in a couple of my web apps. These apps are built using a common code base in the form of webcontrols. recently i change the code that does sorting and selecting on datasets to use dataviews rather than using the  select() method on the datatable. After doing this the error started to return '13' rather than '5' in the error above.

     

    The other thing I have observed is that out of 6 web apps built using these controls (all used decleratively ONLY i.e. no code behind on the web pages) the ones throwing this error uses sort functionality on columns of the dataset that potentially get changed if the value for a particular row is null or empty for example.

     

    In my case i think threading can play a part also as these datasets are cached using the Cache API but sorting/selecting/dataviews also play a part.

     

    I'm going to try and come up with some code to repro this to confirm it is this so will post here as and if.

     

     

    16 апреля 2007 г. 23:14
  • I got the same error message yesterday.  Followed the guidelines to get the fix.  Support was great but really bizarre.

     

    Can I have this hotfix? Sorry the hotfix doesn't exist.  Yes it does, it's just not public.  Well if it's not public, how did you get it? I Googled it and found it on the Microsoft forum.  Well, you still can't have it - it's not public. But it says right here that "Once you get someone on the line..." where upon I was transfered to developer support.  Suddenly, the image of Charlie Sheen going up the river to Cambodia on a patrol boat with self-dialog and really cool 60's rock music playing in the background popped into my mind.

     

    Developer support was great - gave me the hot fix - and, voila, the problem went away.  :-)

     

    18 апреля 2007 г. 12:20
  • Hi,

    Any updates on this?

     

    It seems like for me sorting and updating datatables directly i.e. datatable.select() gives DataTable internal index is corrupted: '5'. and doing the same via DataViews gives DataTable internal index is corrupted: '13'.

     

    These datatables are cached using the Cache API before they are processed on so multithreading may be an issue. However I have not been able to re create this in test code.

     

    Anybody else come across this scenario? Any code to recreate ?

     

     

    Thanks
    25 апреля 2007 г. 11:35
  • I'm also getting this error, but its when executing  a RejectChanges() after a failed delete operation.

     

    This dataset is bound through a binding adapter to a datagridview.  I have three other datasets that are also bound the same way, but do not have the issue.  My application is not multithreaded (unless the datagridview or bindingsource are). 

     

    I haven't tried the hot fix yet, but I had another thought.  Since I plan to distribute this application commercially, what good will the hot fix do me?  Can I update the .Net Framework code when the user installs the application?

     

    Based on the amount of activity I've found on the web related to issues with datasets (especially with .Net 2.0), is it better to just stay away from datasets altogether?

    26 апреля 2007 г. 22:31
  • Okay, I seemed to have given up too soon.  As it turns out, the answer was to move where I was issuing the updates.  I was using the RowChanged and RowRemoved event of the datagrid to issue my updates to give the user the same experience as a spreadsheet.

     

    The proper place to do this appears to be by handling the RowChanged and RowDeleted events of the datatable.  I add a handler in my business class and issue the updates from there.  This works perfectly, and does not give me the internal index is corrupted error.  I assume that either the datagridview or the binding adapter must create a dataview behind the scenes and this causes the error.

     

     

    27 апреля 2007 г. 0:50
  • Dear John,

     

    I think I have expreience the same problem you have with updating the DataSet to a database in the RowChanged of the DataGridView.

    I have also move it to the RowChanged of the DataTable and it seem to fix the problem.

    The thing is it is not always fix the problem.

    Please read my messages in this thread about using SynchornizationContext to ensure it will work prefectly.

     

    Cheers,

    Ido.

    28 апреля 2007 г. 5:06
  • I was able to consistently reproduce this error in an application I'm writing.  My code handled the RowChanged event of the dataTable itself (not a dataGridView) in multiple places..  I managed to find the particular handler that was causing the problem, and the only touching of the dataTable that I could find was to set a value in the row and to call beginEdit() on the row.  I changed the handler so it didn't do either of these things and that seemed to fix the problem.  I tried to write a sample application to reproduce the problem but was unable to, even though I did the same things (calling beginEdit() and changing a row in the rowChanged event of the table) so there must be more going on, but I couldn't figure out what it was.
  • I have an Access database with related tables and when saving one time my program for some reason froze in the middle of saving. Later when I opened it it had only some records saved as expected. The funny thing is when I went to add a related record I got the error:

     

    Message: DataTable internal index is corrupted: '5'.

     

    I clicked the button again to add a record and got:

     

    Message: DataTable internal index is corrupted: '5'.

    Target Site: Int32 RBInsert(Int32, Int32, Int32)

    Stack Trace:    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) .............

     

    My program opens different database files and other access database files were woring fine but that specific one was giving an error so I thought it was the database. I opened it in Accesss and did compact and repair and the next time I opened it it worked fine like it was supposed to. I knew this was a problem with no real known cause or solution so I made a backup of the database first. I looked at it again and the way it works is it adds records with a number as the count. For example the first record would be called "Record 1" then "Record 2" and so on. Like I said my tables are related so I had:

     

    Level 1 Record "Record 1"

    Level 2 Record "Record 1"

    Level 3 Record "Record 1"

    Level 4 Record "Record 2"

    Level 3 Record "Record 2" (Was not in the database but to show the structure)

    Level 4 Record "Record 1" (Was not in the database but to show the structure)

    If you can see how the record giving me problems was adding a record under Level 3 Record "Record 1" giving me an error. After clicking twice to add I got the new record but it was numbered 2 which should have been Record 2. These numbers come from the record counts so there was another record in the table but "lost" not connected to a parent so I got the number 2. After finally getting this record added I tried saving and got an error. So I assume because the file failed to save the first time it got corrupted and in turn corrupted my dataset. I guess if you're having this error in Access databases try a compact and repair.

     

  • I have reproduced this issue in a very simple windows app, no listchanged events, no threading. I have the patch from earlier in the thread applied.  Please let me know if others can get this code to reproduce the error.

     

    I narrowed this down from a much larger project. It reproduces for me everytime. I got it down to the point where changing the AllowDBNull on Column Term from False to True cures the problem.  The funy thing is the particular column is never referenced in the project. Helluva fun way to pull an all nighter....

     

     

    I'm not sure how to post the Typed DataSet since the designer code is so large. The name of the typed dataset is dsQuote. It contains 1 table call dtQuote. dtQuote has 4 fields:

    QuoteID (AutoIncrement=True, AllowDBNull=False,DataType=System.Int32,Unique=True, PrimaryKey)

    Term (AllowDBNull=False, AutoIncrement=False,DataType=System.Int32,Unique=False, DefaultValue=12,NullValue=0)

    TotalCost(AllowDBNull=True, AutoIncrement=False,DataType=System.Decimal,Unique=False, DefaultValue=0,NullValue=0)

    FinancedItemsAmount(AllowDBNull=True, AutoIncrement=False,DataType=System.Decimal,Unique=False, DefaultValue=0,NullValue=0)

     

    P.S. Sorry if there is a better way to post code:

    Code Snippet

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;

    namespace WindowsApplication2
    {
        public class SampleControl : TextBox
        {
            public SampleControl()
                : base()
            {
            }

            private object _value;
            public virtual object Value
            {
                get { return _value; }
                set
                {
                    if (_value != value)
                    {
                        _value = value;
                        this.Text = _value.ToString();
                    }
                }
            }
        }
        public class frmParent : Form
        {
            private System.ComponentModel.IContainer components = null;

            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }

            private void InitializeComponent()
            {
                this.button1 = new System.Windows.Forms.Button();
                this.textBox1 = new SampleControl();

                this.SuspendLayout();
                this.button1.Location = new System.Drawing.Point(461, 207);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 1;
                this.button1.Text = "button1";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                this.textBox1.Location = new System.Drawing.Point(25, 13);
                this.textBox1.Name = "textBox1";
                this.textBox1.Size = new System.Drawing.Size(100, 20);
                this.textBox1.TabIndex = 2;
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(624, 266);
                this.Controls.Add(this.textBox1);
                this.Controls.Add(this.button1);
                this.Name = "frmParent";
                this.Text = "frmParent";
                this.ResumeLayout(false);
                this.PerformLayout();
            }

            private System.Windows.Forms.Button button1;
            private SampleControl textBox1;

            dsQuote _dsSample1 = new dsQuote();
            public frmParent()
            {
                InitializeComponent();

                textBox1.TextChanged += new EventHandler(textBox1_TextChanged);

                _dsSample1.BuildBindings();

                _dsSample1.ReadXml(Application.StartupPath + "\\abcde.agq");

                Binding _binding = new Binding("Value", _dsSample1.bsQuote, _dsSample1.dtQuote.FinancedItemsAmountColumn.ColumnName, true, DataSourceUpdateMode.OnPropertyChanged);
                _binding.ControlUpdateMode = ControlUpdateMode.OnPropertyChanged;
                textBox1.DataBindings.Add(_binding);
            }

            void textBox1_TextChanged(object sender, EventArgs e)
            {
                if (_dsSample1.bsQuote.Position < 0) return;

                dsQuote.dtQuoteRow dqr = _dsSample1.dtQuote[_dsSample1.bsQuote.Position];
                dqr.TotalCost = 10000;
                dqr.FinancedItemsAmount = 50;
            }

            private void button1_Click(object sender, EventArgs e)
            {
                Decimal financedFeeAmount = 0;
                dsQuote.dtQuoteRow dqr = _dsSample1.dtQuote[_dsSample1.bsQuote.Position];
                dqr.FinancedItemsAmount = financedFeeAmount;
            }
        }
    }

     

    The file referenced in thecode is listed below:

    Code Snippet

    <!--
    <?xml version="1.0" standalone="yes"?>
    <dsQuote xmlns="
    http://tempuri.org/dsQuote.xsd">
      <dtQuote>
        <FinancedItemsAmount>1000</FinancedItemsAmount>
        <TotalCost>1000</TotalCost>
        <Term>36</Term>
        <QuoteID>0</QuoteID>
      </dtQuote>
    </dsQuote>

    -->

     

     

    The following code is in the file dsQuote.cs

     

    Code Snippet

    public partial class dsQuote : System.Data.DataSet

    {

    public void BuildBindings()

    {

    _bsQuote.DataSource = this.dtQuote;

    }

    private BindingSource _bsQuote = new BindingSource();

    public BindingSource bsQuote

    {

    get { return _bsQuote; }

    }

    }

     

     

     

     

  • Hello there.

     

    I'm not sure, if my problem is the same as the one, discussed in this thread. But it looks related to me and I didn't finde any thing else on the internet looking like my exception.

     

    The Application has many threads, but all Calls changing the DataSet are laid on a System.Collections.Generic.Queue (using Reflection) and invoced by one thread in the background.

     

    It's a "IndexOutOfRangeException" with the message "An der Position 1386 befindet sich keine Zeile." and following StackTrace:

    bei System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)

    bei System.Data.DataTable.EvaluateExpressions()

    bei System.Data.Merger.MergeDataSet(DataSet source)

    bei System.Data.DataSet.Merge(DataSet dataSet, Boolean preserveChanges, MissingSchemaAction missingSchemaAction)

    bei System.Data.DataSet.Merge(DataSet dataSet, Boolean preserveChanges)

    bei CDBaisys.CDB.loadData(IDbDataAdapter da, String TableName, String SourceTable, Boolean ReadOnly) in N:\aisys\aisys\CDB\CDataBase.cs:Zeile 497.

    bei CDBaisys.CDB.Sql(String SelectQuery, String TableName, Boolean ReadOnly) in N:\aisys\aisys\CDB\CDataBase.cs:Zeile 583.

    bei CDBaisys.CDB.getnxtnr(String myObject) in N:\aisys\aisys\CDB\CDataBase.cs:Zeile 2502.

    18 июня 2007 г. 12:30
  • This thread has been going for more than one year now.  How many years will it take Microsoft to fix this problem?  Any bug that causes corruption of data (duplicated rows) would seem to be a pretty big deal to me, especially in a financial application where we may end up with double payments or other financial damage.

     

     

    21 июня 2007 г. 14:52
  • Dear Don,
    I am not working at Microsoft, but I feel I want to answer your remark.
    I have also experience "Internal Index is corrupted 5" and I am also try all the different solutions with no luck what so ever.
    After almost year of fighting with this bug we have found solution in this very forum and thread which state that Microsoft did not intend that people will use DataView.ListChanged event and to change the underlying DataTable's data inside that event handler.

    After we have understand this issue we change our code as needed and I am happy to say that until now we have not experience "Internal Index Corrupted 5".

    Microsoft also create QFE which available by calling Microsoft support and the QFE number can be found in this thread.

    I agree that there is problem in the design of DataTable and DataView but it is not right to say that Microsoft did not do as much as they can about this issue.

    Thank you,
    Ido.
    26 июня 2007 г. 18:25
  • Dear Ido, i think, your post is inappropriate in this thread. You are trying to justify Microsoft and nothing else. And i think, you probably work with Microsoft - this is the only one thing to explain your post.

    The metter is that programmers from Microsoft have written the code that uses DataView.ListChanged event and changes the underlying DataTable's data inside that event handler.

    As you can see from the stack trace which happened in my case, I am trying  to set the value of DataRow and have the exception in response:

     

    System.InvalidOperationException: DataTable internal index is corrupted: '13'.

    at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)

    at System.Data.DataView.GetRecord(Int32 recordIndex)

    at System.Data.DataView.GetRow(Int32 index)

    at System.Data.DataView.UpdateDataRowViewCache()

    at System.Data.DataView.OnListChanged(ListChangedEventArgs e)

    at System.Data.DataView.IndexListChanged(Object sender, ListChangedEventArgs e)

    at System.Data.DataViewListener.IndexListChanged(Object sender, ListChangedEventArgs e)

    at System.Data.Index.OnListChanged(ListChangedType changedType, Int32 index)

    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)

     

     

    Thank  you.

    28 июня 2007 г. 8:17
  • Dear Microsoft support, please solve the folowing problem

    you have published the hotfix

    (see https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=7251&wa=wsignin1.0)

    Title KB932491
    Release Date 6/20/2007
    Size 37.73 MB
    Version Hotfix
    Category Build
    Milestone
    Description FIX: Unable to auto-attach to ASP.Net applications on Windows Vista Home Edition

    but in details, related to this fix was written (see link on page)

    "The Requested Web Page is Not Available"

     

    but i found another page, related to this topic (see http://support.microsoft.com/kb/932491/)

    where in description was sad

    FIX: Data that is associated with a component that uses the System.Data object may become corrupted in an application that is built on the Microsoft .NET Framework 2.0

    and also sad that described problem will be fixed in service pack or hotfix

     

    My dear friens from Microsof, please investigate this, and give this miserable hot fix (that i hope you already done). it is desirable you publish the link on fix to this forum.

     

    Thank you very much.

     

     

    29 июня 2007 г. 9:26
  • Recently i have installed SP1 for VS 2005 and i have the same problem

     

    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)
      
    ************** Loaded Assemblies **************
    mscorlib
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.802 (QFE.050727-8000)
        CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll

     

     

    29 июня 2007 г. 13:08
  • I agree with Juliy Cesar on this point. I'm setting a value on a row which is then internally fireing events (which cause issues) on the default dataview.

     

    wonder it there are any fixes for this in .Net 3.5?

  • I have been watching this thread for a couple of weeks, since I got the similar kind of “Index” related issue on DataTable, when it is working in a multi -threaded scenario.I shall explain the situation briefly, to get a better understanding of this.

     

    I’m developing a middle-tire component, which populates data as bunch-by-bunch into a DataTable through a background process, while Presentation-tire can access the, so far populated, data in main thread. The background processing is developed by using BackgroundWorker class in framework 2.0. A lock is also applied to Data table to ensure its thread-safety on background processing.

     

    When the Presentation -tire try to access the data from DataTable, exception is getting. I have made both Console and GUI client application to test my middle-tire component.  In console application I’m getting index out of range exception like “There is no row at position 1443.    at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) “. But in GUI application, the exception is “DataTable internal index is corrupted: '5'.  The position of index, which causes the exception, is not stable, and some times it is working fine with out giving any exception.

     

    After watching this thread, I have collected and installed the hotfix “KB 932491”, but that couldn’t help me to get out of this. Is there any other fix or work around to solve this issue? Please help.

    3 июля 2007 г. 12:28
  • I have the same problem. I try writte expression evaluator and I need change data row in ListChanged event.

    I dowload and installed Hot Fix but it still doasn't work.

    Any sollution for this problem?

    6 июля 2007 г. 12:48
  • Hi Anneesh,

     

    The thing is, if you are modifying the data on a background thread while the data is bound to some controls in the UI, then you essentially have two concurrent threads modifying the dataset, even if you lock on the datatable.  Some ways to avoid the threading issue:

     

    1. Push the changes to the main UI thread using a delegate.  I wrote some code to do this in the past.  In your main form, create a function like so:

     

    // Delegate for ProcessWorkerMessage.

    private delegate void delegateProcessWorkerMessage( int MessageType, Object message );

    delegateProcessWorkerMessage delegateProcessWorkerMessageImpl = null;

    private void ProcessWorkerMessageImpl( int MessageType, Object message )

    {

    // Process messages here...

    switch ( MessageType )

    {

    case FormMessage.MSG_APPLY_FILTER:

    ApplyCustomFilter( (string) message );

    break;

    case FormMessage.MSG_RESET_FILTER:

    ApplyCustomFilter( "" );

    break;

    case FormMessage.MSG_SET_STATUS:

    SetStatus( (string) message );

    break;

    case FormMessage.MSG_SET_STATUS_ERROR:

    SetStatusError( (string) message );

    break;

    }

    }

    public void ProcessWorkerMessage( int MessageType, Object message )

    {

    // Process messages here...

    Object [] objParams = { MessageType, message };

    this.BeginInvoke( delegateProcessWorkerMessageImpl, objParams );

    }

     

    then on your background thread you call:

     

    form1.ProcessWorkerMessage(FormMessage.MSG_SET_STATUS, "Scan complete.");

     

    I made this function generic so it takes an enum for message type and an object for the data, so in your case you would serialize changes to the main thread.

     

    Another way to solve this is the "copy on write" approach.  In your background thread, you make a copy of the datatable, modify it, then push the whole thing to the main UI thread and assign it.  The problem with this is you have to watch out for writing over user input on the main thread.  But if you have the main UI thread read only, then this works well.

     

    6 июля 2007 г. 17:06
  • Hi, this is an interesting thing. I also have a dataset as a local cache in a static class. The controls are bound to that dataset. New data is fetched asynchronsly so that the ui can show an animation. I thought, this would not be a 2 thread scenario, because nothing is entered while filling, but if i understand you, it is in fact so that the binding in the ui reacts on the async fill of the dataset and destroys the index....

     

    What can I do to fill the dataset async (so that the animation on the ui works) and to be sure, that the binding does not occur? Is SuspendBinding a way? But how to suspend all bindings? It's not possible with currencymanger[..] because there is not possibility to list all bindings...

     

    Quiet confusing

    6 июля 2007 г. 17:36
  • This is a case where copy on write would work ok.

     

    Before updating data, lock the UI so users cannot enter data.  Then on the background thread, make a copy of the dataset (using clone I believe will work).

    On the background thread, modify the copy of the dataset to your hearts content until you are finished (while UI animation is running).

    Once background thread is finished, background thread assigns the new dataset to the bindings, overwriting the old one.

    Then last step is to re-enable the UI.

     

    I worked with a customer about 3-4 years ago that was using a dataset and associated dataviews inside an ASP.NET application where the dataset was a centralized cache.  We used this same approach to allow multiple threads to modify the data.  Each thread would lock a centralized global lock object, then make a copy, increment a checkout counter, then release lock.  Thread would modify the data copy (take as long as it likes) then lock the global lock, check the counter and if the counter was still 1, then copy over the dataset.  This worked out well for the customer because writes were infrequent, the cost of copy  and global lock was not a huge issue.  In the end, what we were trying to do is write a concurrent database server, so we finally agreed this is the purpose of having a database server and got rid of all the crazy code and life became simple again.

     

    The thing about dataset is that it is not thread friendly, even today with the fix.  It was designed for single threaded UI apps.  This is why it creates the indexes to improve perf but the cost is a lack of thread safety.  I've written a few multi-threaded ui apps in my day, and the way I typically deal with dataset is as follows:

     

    1. Perform all write operations on the main UI thread.  This means posting writes from background threads to main thread.

    2. To avoid "eventing" data modification issues (like corrupting the index of the dataset), don't modify data in data driven events.  It just takes a little more thinking when you design the UI but it can be done.

    3. Be careful when storing things in dataset that you don't modify the stored objects outside of dataset.   We had a customer who was storing custom objects in a dataset and then modifying the objects both in the dataset and outside the dataset at the same time.  This confuses the index because the index is maintained by dataset code.

    4. Be careful when using DataViews.  Just remember creating a DataView is a write operation on a DataSet.  So creating a DataView on background thread is a big NO-NO, this is a write operation.  Creating a DataView will drill into the dataset and add an index to the collection of indexes in the dataset (if an appropriate index is not available).

     

    But this is me, mileage may vary.  I'm not a huge GUI programmer so take this with a grain of salt.  I will forward this thread to the DataSet program manager again so he can chime in here.

     

     

     

     

    6 июля 2007 г. 18:00
  • One other note.  A long while ago I came up with a brilliant idea of writing a generic pending modifications queue for dataset.  This would allow background thread or any code anywhere (even in data driven events) to post changes to dataset that would later be queued and performed on the main UI thread.  I thought it would be possible to copy off the datarow and do this in a generic fashion but at the time creating a new datarow was a write operation so this did not work.

     

    But in general the idea is sound, but making it happen generically might be a bit of work.  But you could do something like create a bit of code that stores off a copy of the datarow, the modifications (or new values), some action like {insert, update, delete}, the target datatable, etc...  These would be queued into a fifo in a thread safe manner.

    When you queue something, this auto-triggers a delegate on the UI thread to perform the actions. Delegate on UI thread locks the queue and cleans it out.

     

    But in my life I always have more ideas than time to implement them, so I never got around to this one.  Would be a good small project for CodePlex.

    6 июля 2007 г. 18:10
  • BUT, Dear   Matt Neerincx from [MSFT]

     

    I use the folowing construction to call method that change DataTable, and got the paltry exception (see SUbj )

    ...

    m_MainForm.BeginInvoke(request.Callback, new object[] { results });

    ...

     

    as i understand, this means  the request.Callback method is executed in main thread, because m_MainForm is the main form of the application. consequently  modification of DataTable occurs in the same thread.

    Im sorry ,but your fabrication about thread non-safty behaviour of the datatable is not expalins the real reason of this crush.

     

    Thank you for your care about our troubles.

    7 июля 2007 г. 10:33
  • > Once background thread is finished, background thread assigns the new dataset to the bindings, overwriting the old one.

    > Then last step is to re-enable the UI.

     

    For better reading:

    Dataset Cache ;

    Dataset CopyOfCache;

     

    I did'nt understand this step. After I updated the data in CopyOfCache in the Async Method I have to bring the data back to the Cache. How could this be done?

    I think if I do something like Cache = CopyOfCache I will loose my bindings... The Question is hot to assing the bindings to CopyOfCache or copy the data back to Cache...

     

    Thanks... I've understood the main thing... I hope I will get that to work Smile

    7 июля 2007 г. 12:18
  • I'm yet another user with the same problem. I have tried applying hotfix 932491, but it hasn't made a difference. I've since uninstalled this hotfix.

     

    Like Aneesh, I have a multi-tier, multi-thread Windows application. At unpredicitable times, I get the "DataTable iinternal index is corrupted: '5'" error as well as the "DataTable internal index is corrupted: '13'" error. I also get the IndexOutOfRange exception thrown with a message like "There is no row at position <nnn>".

     

    I have a grid that is bound to a datatable. In a background thread, I add/remove rows from the datatable. As you have already explained, this means that I have two concurrent threads modifying the datatable, even if I do try to lock on the datatable.

     

    Like Rudsen, I'm trying to follow your suggestion to "copy on write", but I can't figure out how to seal the deal. I could clone the original datatable (Cache) to make CopyOfCache and modify that instead. But then what? How do I safely update my original datatable and/or change my grid's bindings?

    10 июля 2007 г. 19:32
  • Ok, here are the steps I would use:

     

    1. Lock UI.  This means setting dataGrid1.Enabled = False for example.

    2. Make copy of data table.

    3. On background thread, modify copy of data table.

    4. Once modifications are complete, signal main thread.

    5. Main thread takes copy of datatable, assigns to datagrid1.DataSource.

    6. Unlock UI.

     

    If you want user to have ability to modify data on main UI thread at the same time background thread is modifying it, then the design is more complex.

     

    To allow UI + background concurrent modification, the simplest solution is to serialize all modifications to main UI thread.  You can use a delegate to push the modifications to the main UI thread.  Then all modifications to datatable are coming thru message loop and thus are serialized.  It is just as if the background thread is typing into the datagrid along with user in other words.  But as I mentioned earlier there is not a nice clean generic way to do this that I can think of.  The problem is calling InsertRow for example is a write operation.

    10 июля 2007 г. 19:52
  • We used to get the dreaded "DataTable internal index is corrupted...".  After applying the patch, the problem went away.  Picture a form with two panels. The first panel contains a grid used for navigation plus it can also add and delete rows with the imbedded navigator.  The grid is bound to bsEmployee.  The second panel contains a "form layout view" with a bunch of controls to edit a single row.  Each field is also bound to bsEmployee.  Because we were adding a row with the grid but entering the data in the second panel, the underlying ado framework stuff blew up with the "index is corrupted" error. Once the patch was applied, the problem went away.  To the best of our knowledge, threading was not involved.

     

    With that said, the form also uses background threading to update lookup tables and to also get the less important stuff associated with a multi-table dataset.  The model we are using is to merge the changes (obtained on a background thread) with the dataset on the GUI thread.  So far, it works perfectly.

     

    /* The final data merging has to be done on the GUI thread */

    private delegate bool UpdateDataSetDelegate();

    private bool UpdateDataSet()

    {

    bool ok = false;

    if (_GUISync.InvokeRequired)

    {

    ok = (bool) _GUISync.Invoke(new UpdateDataSetDelegate(UpdateDataSet), null);

    }

    else

    {

    try

    {

    this.AcceptChanges();

    this.Merge(_dsNewData, false);

    this.AcceptChanges();

    NoteMaxTimestamps();

    ok = true;

    }

    catch (System.Exception ex)

    {

    _log.Warn("UpdateDataSet merge failed", ex);

    ok = false;

    }

    return ok;

    }

    return ok;

    }

     

     

     

     

    10 июля 2007 г. 21:16
  • I'm getting this error.

     

    I installed the fix from NDP20-KB932491-X86.exe

     

    The error is still happening. I have also installed sp1 for .net framework 2.0. Is it possible my application isn't targeting the new sp1 version? What can I do?

     

    Single Threaded app. I am calling the delete method through the bindingsource,

     

    ((DataRowView)(this.BindingSource.Current)).Row.Delete();

     

    The error only seems to occur when I set a datetime column in the row to a value.

     

    help

    19 июля 2007 г. 17:58
  • I have been struggling with the bug for a couple of weeks. The System.Data.RBTree index becomes corrupt and throws "DataTable internal index is corrupted: '5' ".

     

    My example is a single threaded application with no UI or databinding and I have already installed the hotfix.

     

    The exception is thrown from the method System.Data.RBTree.RBInsert() because root_id is not equal to 0 (when it should be).

     

    Here is a snippet of my test application that reproduces the problem (although this snippet is not enough to debug the problem, so I am looking for a Microsoft developer to send the full source to).

     

    The exception is thrown every time on the third iteration through the "for" loop.

     

    This bug is preventing us from shipping.

     

    Thanks,
    Fernando

     

    Code Snippet

          // In this code sample, currentTrial aggregates a DataRow. 

          private void ReproduceDataTableBug(MeasurementDataObject measurement)
           {

                for (int i = 0; i < 10; i++)
                {
                    NriTrial currentTrial = BusinessServices.Instance.GetNewNriTrialForEdit(measurement, 128);

                    currentTrial.DataPoints[0] = 1.0f;

                    currentTrial.N1XValue = 1.0f;
                    currentTrial.N1YValue = 1.0f;
                    currentTrial.P2XValue = 1.0f;
                    currentTrial.P2YValue = 1.0f;
                    currentTrial.CurrentLevel = 2;
                    currentTrial.ActualGain = 3.0f;
                    currentTrial.ActualIterations += SAMPLE_SIZE;
                }     
            }

     

     

    26 июля 2007 г. 1:06
  • I'm getting the dreaded "DataTable internal index is corrupted again".  What I'm discovering is that if you have a grid bound to a binding source, if you add new rows to the underlying datasource directly, the data table internal index will become corrupted.  As a workaround, I simulated a user pressing the add button of the bound data navigator and adding the row that way.

     

    Here's how I did it: Created a grid view with an embedded navigator and bound it to binding source "bsRegistration". Thing works great.

     

    Now I've added a smart card reader which gets some info and adds a row to the underlying datasource of bsRegistration: dsEventSet.CERegistration.AddCERegistrationRow(ceRegRow) // with this code, the data table starts getting internal index corruption.

     

    ------------------ Now for some trickery to simulate the user adding the new registrant ----------------
    1) ceRegRow now becomes _ceRegRow (module level variable)
    2) rather than adding the row to the data set, simulate button press: gridRegistration.EmbeddedNavigator.Buttons.Append.DoClick();
    3) Handler for EmbeddedNavigator button click:
    void EmbeddedNavigator_ButtonClick(object sender, NavigatorButtonClickEventArgs e)
    {
      if ((e.Button.ButtonType == NavigatorButtonType.Append) && (_ceRegRow != null))
      {
        bsRegistration.AddNew();
        e.Handled = true;
      }
    }

    4) Get the card reader data in bsRegistration events:
    bool _AddingNew = false;
    private void bsRegistration_AddingNew(object sender, AddingNewEventArgs e)
    {
      _AddingNew = true;
    }

    /* Card reader - Capture NonMemberID or RealtoID */
    private void bsRegistration_CurrentChanged(object sender, EventArgs e)
    {
      if (_AddingNew)
      {
        _AddingNew = false;
        if (_ceRegRow != null)
        {
          if (!_ceRegRow.IsNonMemberIDNull())
          {
            ((DataRowView)bsRegistration.Current).Row["NonMemberID"] = _ceRegRow.NonMemberID;
          }
          if (!_ceRegRow.IsRealtorIDNull())
          {
            ((DataRowView)bsRegistration.Current).Row["RealtorID"] = _ceRegRow.RealtorID;
          }
          _ceRegRow = null;
        }
      }
    }

    The internal index corruption goes away.

     

    26 июля 2007 г. 13:53
  • I had this problem too but it was fixed by applying Hotfix KB932491

     

    I have a single threaded Windows Forms app.

    It uses DataSets through BindingSources and shows different DataTables of the same DataSet through different Forms.

    I'm using cascaded Binding Sources to get Master/Child functionality.

    I have some Expression columns where the Expression is set and cleared as forms are opened and closed.  My Expressions typically count the number of child records in related DataTables.

     

    I don't fiddle with RowChanged, ListChanged, CurrentChanged

     

    The Exception was being thrown on ...BindingSource.EndEdit() when one of my forms was being closed after fields had been updated.

     

    All seems to be working fine now.

     

    I just need to know when this Hotfix is going to appear in a fully regression tested .Net Framework ServicePack.

     

    31 июля 2007 г. 13:28
  • My application is ASP.net 2.0 Web application.

    I am storing dataset with Four tables in the Web Cache. After Retrieving the data, I am doing Select on the DataTable.

    I am not able to reproduce this problem. One of my Business user got this error.

     

    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.RBTree`1.Insert(K item)
    at System.Data.Index.InitRecords(IFilter filter)
    at System.Data.Index..ctor(DataTable table, Int32[] ndexDesc, IndexField[] indexFields, DataViewRowState recordStates, IFilter rowFilter)
    at System.Data.Select.CreateIndex()
    at System.Data.Select.SelectRows()
    at System.Data.DataTable.Select(String filterExpression, String sort)

    I have gone through the whole blog.

    1. Should i Lock my dataset ?
    2. I can not create a copy of the Dataset after fetching from cache as this will degrade the performance on the web server.
    3. Is Dataset thread safe in ADO.net 2.0?
    4. Do i have to avoid using Select on DataTable?
    5. Is this problem related to Caching a Dataset and only one copy is shared between all the web requests.
    6. Is there a definte fix for this problem.
    31 июля 2007 г. 15:31
  • hi guys,

     

    to me it finally helped to simply AVOID the BindingSource's CurrentChanged event.

     

    without this event i dont get this nerving error again....

     

    if you need a "change" event you can use the "xDataSet.tableRowChange" event in the

    dataset itself....just inherit your dataset and then override that event.

     

    hope this helps some of u.

    foxxed

    27 августа 2007 г. 12:14
  •  

    Unfortunately , i do not use CurrentChanged event of binding source , instead of this event i use CurrentCellChanged of datagrid, may be it depends on  CurrentChanged, i do not know.
    28 августа 2007 г. 9:29
  • Hi,

    I'm having the same problem, without multi-threading (Windows Forms application - only main UI thread).
    But I suppose the cause of many of the people having the issue is somehow related to the "CurrentChanged" of the binding.
    (CurrencyManager.CurrentChanged)

    The grid that I'm using subscribes to this in order to raise SelectionChanged event. (Probably the "CurrentCellChanged" is another one). I got it from the stack trace.

    My case is rather straight forward, and I haven't thought of a workaround yet. I want to cancel the changes of the user if the user moves to another row in the grid. This means that I have to listen to "SelectionChanged" event of the grid, and call "RejectChanges" in the handler.

    I guess the binding / dataset implementation rely on the currency manager's properties, and they are not fully consistent when the current selection is changing.

    (I haven't tested the KB Hotfix yet, but I suppose that would not help, as I want to distribute the application on many machines)

    -Hamed

    22 октября 2007 г. 9:30

  • I struggled for a day with the issue, and it turns out to be an issue of updating dataset in the middle of the binding context being updated. I tried many ways to force the index to be re-built, nothing worked.

    Finally, I'm using the "SynchronizationContext" class in "System.Threading", and update the dataset after the event handlers are complete.

    I'm happy with the "SynchronizationContext" solution, as this way fixes other minor issues too.


    22 октября 2007 г. 14:51
  • This is interesting.. over a year and no solution.

    I have a VERY simple app. A Windows form with text boxes, bound to a BindingSource. A Binding Navigator, a tableAdapter and a Dataset.

    It doesn't get much simpler than this.  No multi-threading.

    if I use BindingSource.Find(), eventually, when navigating back and forth on the BindingNavigator, I'll get the corrupted index exception.

    if I use TableAdapter.Update() on the BindingSource.CurrentItemChanged event handler, eventually I'll get the corrupted index exception.

    To me, this indicated that the BindingSource is broken.

    I'm going to have to manage everything manually, using SqlDataAdapters in code and manually created datasets.

    Feels like going back to DotNet 1.0  and the original ADO.


    31 октября 2007 г. 9:20
  • Tim,

     

    Are you running Visual Studio 2008 Beta 2? We made a number of fixes in 2008 that address this error.

     

    Thanks,

    Erick

     

    31 октября 2007 г. 19:25
    Модератор
  • Come on...you can't tell us to wait untill YOU release vs2008...my company will adopt it in 2 years time at least...what do we do untill then? reverting to traditional ADO is not an option for me. Good luck to everyone!

     

    pier

    6 ноября 2007 г. 11:25
  • Since ADO.NET is in the 2.0 framework, does this mean a service pack for 2.0 is coming out to address this bug?

    6 ноября 2007 г. 13:21
  • As part of Visual Studio 2008 there are a number of fixes for 2.0 assemblies, including some that will fix this issue. Once Visual Studio 2008 is released, these fixes will be available for 2.0. Installing VS 2008 is not a requirement, but the fixes are only available in 2008 at this time.

     

    Just to be clear, the fixes for 2.0 bits (including DataSet) are being beta tested as part of VS 2008, but will be released on their own - VS 2008 will not be a requirement to get these fixes.

     

    The main reason that I asked is that I want to make sure that there isn't another issue that we didn't cover in our work for VS 2008. If you can install VS 2008, just for updates, but continue to use VS 2005 in the way that you are doing now, this will help determine if the problem will be fixed. Does this make sense?

     

    Thanks,
    Erick

    6 ноября 2007 г. 18:50
    Модератор
  • If I understand this, what you are saying is that projects developed using VS2008 targeted to the 2.0 framework will be incompatible to the 2.0 framework deployed at client sites. The reason being that 2.0 for VS 2008 is different than 2.0 for VS 2005.  If this is the case, it does not make any sense at all.  Is there going to be a big disclaimer on the VS 2008 box that says "Not For Deployment Until 2.0 SP1 is released"?

    8 ноября 2007 г. 15:37
  • Hi Erick!

     

    If we can't test now, on VS 2005, how do we know the issue is addressed in the fix for Framework 2.0. (Whenever it comes)

    Last fix did not do any good. (to my apps)

    If next fix do the same to our app's, i se the years go by verry fast:-(

     

    Regards

    Anders

    13 ноября 2007 г. 8:01
  • The installation for Visual Studio 2008 includes a set of fixes for the 2.0 version of the Framework. So if you install VS 2008, you will get the fixes. This does not mean that you need to use VS 2008, just that you need to install it. Once VS 2008 is released, I believe that the 2.0 updates will be released as a standalone package.

     

    Thanks,

    Erick

    13 ноября 2007 г. 20:29
    Модератор
  • I installed the 2.0 SP1 framework that was released on Nov 22, 2007, and the problem has not gone away.
    22 января 2008 г. 17:42
  • We have the 2.0 SP1 installed with VS 2005, and I do still get the error. There are two, actually:

    DataTable internal index is corrupted: '5'
    DataTable internal index is corrupted: '8'

    I'm not sure if the number refers to the corrupted index, or some other internal code.

    Is there a way to lock the dataset so that if there is another thread trying to access the data, then that thread will wait?


    Jim
    22 января 2008 г. 18:45
  • I'm already doing that, it doesn't help.  This is not a thread safety problem, or at least, that's not the only way to reproduce it.  In our case, we're trying to modify cells in an Infragistics grid from the InitializeRow event handler.  As a workaround, I am placing that portion of the event handler inside a SynchronizationContext.Post() and directly modifying the DataRow.  Normally you'd use SynchronizationContext.Post() to solve a cross-threading problem, but in this case, it's useful for just getting code out of the DataView.ListChanged event handler (which apparently is where Infragistics fires their InitializeRow event).  I'm already on the UI thread, so I know this is not a cross threading issue.
    22 января 2008 г. 18:52
  • Curtis,

     

    Can you let me know what the culture of the current thread is? Also, please let me know what the data types of your columns are.

     

    Are you using a string expression anywhere (filter and/or sort)? If so, please use explicit conversion functions and let me know if this helps. We're trying to narrow down the problem area.

     

    Thanks,

    Erick

     

    23 января 2008 г. 2:14
    Модератор
  • CurrentThread.CurrentCulture and CurrentThread.CurrentUICulture are both set to "en-US".

    Our data types are:
    string, string, Boolean, string, DateTime, string, DateTime, Decimal, string, Int32, string, string, string, string, Boolean

    We aren't using any filter expressions or sorts, although since it is an Infragistics grid, and they support sorting by clicking on the column header, I suppose they might be doing some sorting behind the scenes that would impact this behavior.

    Curtis

    23 января 2008 г. 15:44
  • Curtis,

     

    Do any of the string columns contain data that could be implicitly converted to another type (e.g., a string column containing DateTime like strings)?

     

    Can you check the Sort expression at various points in your code, especially just before the corruption? If there is a sort occuring, having the string will be very helpful.

     

    Thanks,

    Erick

     

    23 января 2008 г. 21:27
    Модератор
  • So far as implicit type conversions go, when populating the DataTable initially we are passing strings into all the columns except the Booleans.  I didn't suspect that as a potential source of problems, but will try changing our code to do an explicit conversion first. 

    There was one place specifically in an event handler (after the data had been populated via strings, as described above), where we were trying to update the value in a DateTime column by setting the grid's cell value.  I could comment out that line of code and the corruption would go away.  I tried setting the cell value to a string containing the date/time, and also using DateTime.Parse(string).  I saw corruption either way.  I also tried setting the DataRow[columnName] directly, and still saw the corruption whether passing it a string or a DateTime.

    The sort expression on DataTable.DefaultView.Sort is an empty string right before the corruption happens.  Again, though, if Infragistics is setting the Sort expression on a different DataView, I don't have visibility into that.  We aren't doing anything explicitly to sort, and grid.DisplayLayout.Bands[0].SortedColumns is empty.
    24 января 2008 г. 17:00
  • Can you post the call stack during your call where you update the value (the line that causes corruption)?

     

    Thanks,

    Erick

    24 января 2008 г. 21:53
    Модератор
  • Here is the stack trace from our application when the crash occurs:

       at System.Data.RBTree`1.RBInsert(Int32 root_id, Int32 x_id, Int32 mainTreeNodeID, Int32 position, Boolean append)
       at System.Data.RBTree`1.RBInsert(Int32 root_id, Int32 x_id, Int32 mainTreeNodeID, Int32 position, Boolean append)
       at System.Data.Index.InsertRecord(Int32 record, Boolean fireEvent)
       at System.Data.Index.ApplyChangeAction(Int32 record, Int32 action, Int32 changeRecord)
       at System.Data.DataTable.RecordStateChanged(Int32 record1, DataViewRowState oldState1, DataViewRowState newState1, Int32 record2, DataViewRowState oldState2, DataViewRowState newState2)


    And here's the stack trace where we update the value:

    >    Spillman.Modules.JailModule.dll!Spillman.Modules.JailModule.PropertyIssue.IssueItemsDialog.issueItemsSpillmanGrid_InitializeRow(object sender = {Spillman.Framework.UI.Controls.Grid.SpillmanDBGrid}, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e = {Infragistics.Win.UltraWinGrid.InitializeRowEventArgs}) Line 162    C#
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.UltraGrid.OnInitializeRow(Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) + 0x4c bytes   
         Spillman.Framework.UI.Controls.dll!Spillman.Framework.UI.Controls.Grid.SpillmanGrid.OnInitializeRow(Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e = {Infragistics.Win.UltraWinGrid.InitializeRowEventArgs}) Line 1048 + 0xa bytes    C#
         Spillman.Framework.UI.Controls.dll!Spillman.Framework.UI.Controls.Grid.SpillmanDBGrid.OnInitializeRow(Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e = {Infragistics.Win.UltraWinGrid.InitializeRowEventArgs}) Line 617 + 0xb bytes    C#
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.UltraGrid.FireEvent(Infragistics.Win.UltraWinGrid.GridEventIds id = InitializeRow, System.EventArgs e) + 0x7b5 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.UltraGrid.FireInitializeRow(Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) + 0x50 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.UltraGridRow.FireInitializeRow() + 0xb8 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowsCollection.FireInitializeRow(System.Collections.IList rows) + 0x9b bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowsCollection.InitNonGroupByRows(System.Collections.IList fireInitializeRowOnTheseRows) + 0x169 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowsCollection.SyncRowsHelper(System.Collections.IList boundList) + 0x51f bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowsCollection.SyncRows() + 0x44b bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowsCollection.EnsureNotDirty() + 0x49 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.ScrollCountManagerSparseArray.VerifyAgainstScrollVersion() + 0x58 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.ScrollCountManagerSparseArray.GetItemAtVisibleIndex(int visibleIndex = 0) + 0xe bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowsCollection.GetRowAtVisibleIndex(int visibleIndex = 0, bool includeSpecialRows) + 0x59 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowsCollection.GetFirstVisibleRow() + 0x9 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowScrollRegion.FirstRow.get() + 0x17b bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowScrollRegion.GetMaxScrollPosition(bool scrollToFill = true) + 0x141 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowScrollRegion.EnsureScrollRegionFilled(bool calledFromRegenerateVisibleRows) + 0x5a bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowScrollRegion.RegenerateVisibleRows(bool resetScrollInfo = true) + 0x4e bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowScrollRegion.WillScrollbarBeShown(Infragistics.Win.UltraWinGrid.ScrollbarVisibility assumeColScrollbarsVisible = Check) + 0xc9 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowScrollRegion.PositionScrollbar(bool resetScrollInfo = false) + 0x77 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.ScrollRegionBase.SetOriginAndExtent(int origin, int extent) + 0x18 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.RowScrollRegion.SetOriginAndExtent(int origin, int extent) + 0x1c bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.DataAreaUIElement.ResizeRowScrollRegions() + 0xdf bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.DataAreaUIElement.PositionChildElements() + 0x28 bytes   
         Infragistics2.Win.v7.3.dll!Infragistics.Win.UIElement.VerifyChildElements(Infragistics.Win.ControlUIElementBase controlElement = {Infragistics.Win.UltraWinGrid.UltraGridUIElement}, bool recursive = false) + 0x51 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.DataAreaUIElement.VerifyChildElements(Infragistics.Win.ControlUIElementBase controlElement, bool recursive) + 0xf0 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.DataAreaUIElement.Rect.set(System.Drawing.Rectangle value) + 0x37 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.UltraGridUIElement.PositionChildElements() + 0xabc bytes   
         Infragistics2.Win.v7.3.dll!Infragistics.Win.UIElement.VerifyChildElements(Infragistics.Win.ControlUIElementBase controlElement = {Infragistics.Win.UltraWinGrid.UltraGridUIElement}, bool recursive = true) + 0x51 bytes   
         Infragistics2.Win.UltraWinGrid.v7.3.dll!Infragistics.Win.UltraWinGrid.UltraGridUIElement.VerifyChildElements(Infragistics.Win.ControlUIElementBase controlElement, bool recursive) + 0x2f bytes   
         Infragistics2.Win.v7.3.dll!Infragistics.Win.UIElement.VerifyChildElements(bool recursive) + 0x30 bytes   
         Infragistics2.Win.v7.3.dll!Infragistics.Win.ControlUIElementBase.VerifyIfElementsChanged(bool verify, bool syncMouseEntered = false) + 0x26 bytes   
         Infragistics2.Win.v7.3.dll!Infragistics.Win.ControlUIElementBase.CurrentCursor.get() + 0x24 bytes   
         Infragistics2.Win.v7.3.dll!Infragistics.Win.UltraControlBase.Cursor.get() + 0x26 bytes   
         System.Windows.Forms.dll!System.Windows.Forms.Control.WmSetCursor(ref System.Windows.Forms.Message m) + 0x74 bytes   
         System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x3ce bytes   
         System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0xd bytes   
         System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x36 bytes   
         System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 32, System.IntPtr wparam, System.IntPtr lparam) + 0x5a bytes   
         System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DefWndProc(ref System.Windows.Forms.Message m = {msg=0x20 (WM_SETCURSOR) hwnd=0x3c0e58 wparam=0x3c0e58 lparam=0x2000001 result=0x0}) + 0xcc bytes   
         System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x5 bytes   
         Infragistics2.Win.v7.3.dll!Infragistics.Win.EditorWithMask.AccessibleTextManager.AccessibleTextSubclasser.WndProc(ref System.Windows.Forms.Message msg) + 0x43 bytes   
         System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 32, System.IntPtr wparam, System.IntPtr lparam) + 0x57 bytes   
         [Native to Managed Transition]   
         [Managed to Native Transition]   
         System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(int dwComponentID, int reason = -1, int pvLoopData = 0) + 0x273 bytes   
         System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0x17d bytes   
         System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x53 bytes   
         System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x2e bytes   
         Spillman.Framework.UI.FormManagement.dll!Spillman.Framework.UI.FormManagement.FormLauncher.LaunchChildForm(object argument = {Spillman.Framework.UI.FormManagement.FormInfo}) Line 318 + 0x8 bytes    C#
         mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x57 bytes   
         mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x81 bytes   
         mscorlib.dll!System.Threading.ThreadHelper.ThreadStart(object obj) + 0x4a bytes   



    Note that updating the value seems to set up the dataset for failure later on, the crash does not occur until later.
    5 февраля 2008 г. 18:02
  •  CurtisP wrote:
    Here is the stack trace from our application when the crash occurs:

    .
    .
    .

    Note that updating the value seems to set up the dataset for failure later on, the crash does not occur until later.



    Hi Curtis, I don't know if this will help you or not, but I recently had to debug this same issue. Your last statement there sounds like something I myself had said when I finally traced the cause of the issue.

    Our process goes something like this: We create a new blank DataRow, populate it with default data, then add it to the DataTable. That table belongs to a DataView which we use to databind to a grid.

    I discovered that there was code which had been added that was populating some columns with data after the new row was added to the DataTable.

    I was able to trace the error we were getting down to that code that was populating data after the new row was added to the DataTable. After about three times of add row/change data/add row/change data, the next new row to be added to the DataTable would cause the "Index is corrupted"  error to appear. I had to remove the code which was populating data after the row was added down to the method which populates the newly created row before the row was added. For me, this "fixed" the issue.

    Hope this is helpful,

    Jim

    5 февраля 2008 г. 18:50
  • I am getting this error using Visual Studio 2008 Professional version 9.0.21022.8 RTM in a solution using the .NET 3.5 Framework.

     

    It's occuring on the "assemblyBindingSource.EndEdit();" line.  However, if I change the method to a "SuspendBinding()" it does the same thing.  It might happen on other method calls to my BindingSource, but I only tried those two.

     

    My application contains a WCF service middle tier,  hosted by IIS.  I get the data from this middle tier using my GetLookupTables() and GetAllAssemblies() methods.  My dataset contains a one to many relationship (with cascade update on) from my AssemblyTable and my ScheduleTable.

     

    The error occurs when I change a value on a control (like a textbox) which is bound to the AssemblyTable.  For some reason I never get the error if I only only change a value on a control bound to the ScheduleTable.

     

    I hope this helps.

     

    public partial class CoordinatorPortal : Form

    {

    CoordinatorWebClassClient coordinatorWebClassClient = new CoordinatorWebClassClient();

    ...

     

    public CoordinatorPortal()

    {

    InitializeComponent();

    coordinatorDataSet.Merge(coordinatorWebClassClient.GetLookupTables());

    coordinatorDataSet.Merge(coordinatorWebClassClient.GetAllAssemblies());

    ...

    }

     

    private void saveToolStripButton_Click(object sender, EventArgs e)

    {

    assemblyBindingSource.EndEdit();

    scheduleBindingSource.EndEdit();

    coordinatorWebClassClient.UpdateAssembly(coordinatorDataSet);

    coordinatorDataSet.AcceptChanges();

    enableModeExtender.SetMode(EnableModeExtender.FormMode.Save);

    refreshScheduleControls();

    }

     

    ...

    ...

    ...

    }

    15 февраля 2008 г. 21:45
  • I could replicate the problem I am having, every time.  I found a solution to my problem.  I narrowed the my code down the the following.

     

     

     

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Linq;

    using System.Text;

    using System.Windows.Forms;

    using ClassLibraryTest.CoordinatorService;

    namespace FormTest

    {

    public partial class Form1 : Form

    {

    CoordinatorWebClassClient coordinatorWebClassClient = new CoordinatorWebClassClient();

    //bool dataLoad = false;

    public Form1()

    {

    InitializeComponent();

    coordinatorDataSet.Merge(coordinatorWebClassClient.GetAllAssemblies());

    //dataLoad = true;

    }

    private CoordinatorDataSet.AssemblyRow currentAssembly()

    {

    return (CoordinatorDataSet.AssemblyRow)(((DataRowView)assemblyBindingSource.Current).Row);

    }

    private void button1_Click(object sender, EventArgs e)

    {

    //dataLoad = false;

    coordinatorDataSet.Assembly[0].Description = "Test";

    //dataLoad = true;

    }

    private void assemblyListBox_SelectedIndexChanged(object sender, EventArgs e)

    {

    //if (dataLoad)

    //{

    int assemblyId = currentAssembly().Id;

    coordinatorDataSet.Merge(coordinatorWebClassClient.GetAssembly(assemblyId));

    //}

    }

    }

    }

     

    I have a coordinatorDataSet object on the form, which contains an Assembly DataTable object.

    I have an assemblyBindingSource object on the form, which is bound to the coordinatorDataSet.

    I have a reference to an coordinatorWebClass which I'm using to get data to put into my coordinatorDataSet.

    I have an assemblyListBox control on my form which is bound to the assemblyBindingSoruce object.

    I have a button on the form, which changes data in the Assembly DataTable object.

    I could have replaced my button with a bound control, and an AssemblyBindingSource.EndEdit with the same results.  (Essentially does the same thing)

     

    I believe that my problem is happening because I have a ListBox object bound to a DataTable, and I am handling the SelectedIndexChanged event which re-populates my DataTable.  When my constructor fires the Merge command to intially fill the table, it causes the index to change in the ListBox, which launches another Merge command.  This causes two merges to happen at the same time.  I added the a bool dataLoad flag which prevents this from happening, which fixes my problem.

     

    For some reason, my currentAssembly() function has something to do with the problem, but I haven't figured out how.  If I remove that function, and do what its doing in my SelectedIndexChanged event, that also fixes the problem.

    21 февраля 2008 г. 22:21
  • I downloaded the hotfix, but I cannot install it, it says the installer could not find the program to be updated or the incorrect version is installed. What exactly is it looking for?
    2 апреля 2008 г. 11:57
  • System info: .NET Framework 2.0.50727.832, Visual Studio 2005 Professional with SP1

    I downloaded and applied the Hotfix, but that didn't fix the problem. In fact, it seems the Hotfix wasn't even installed, because all versions of System.Data.dll on my computer are version
    2.0.50727.832, whereas the KB article says they should be v2.0.50727.802.

    In my case, the code that causes the crash is:

    dataRow.Column = myValue;

    and the associated stack trace is:

       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)


    Digging in
    System.Data.RBTree<K> with Reflector, I'm pretty sure that it's this code in the RBInsert() method that's throwing the exception:

    if (root_id != 0)
    {
      throw ExceptionBuilder.InternalRBTreeError(RBTreeError.InvalidStateinInsert);
    }


    because
    RBTreeError.InvalidStateinInsert == 5.

    Microsoft, YOU NEED TO FIX THIS. This bug has been around for over two years and it STILL hasn't been resolved. Just because it only happens to 0.001% of people using the Framework, doesn't give you the right to ignore it!
    7 апреля 2008 г. 11:11
  • Rather than assigning myValue directly to dataRow.Column,  try assigning it to the edit value of the bound control.  That's what I did to avoid the conflict.  Also, isn't the syntax dataRow["columnName"] = myValue?

    7 апреля 2008 г. 12:45
  • You comment:

     

     ...try assigning it to the edit value of the bound control...

     

    What would be the exact syntax for this?

     

    Thanks!

    17 апреля 2008 г. 6:19
  • The issue I ran into was adding a new row where I had two controls competing for the same binding source.  Because of a requirements change, the piece of code where I dealt with the conflict that corrupted the internal index is somewhere out there in the old bit bucket.

     

    With that said,  here is an approach resulting from an experiment. In a new windows form project:

     

    1) Add a dataset.  Add a table adapter to it referencing Northwind.Categories.

     

    2) Add the dataset to your main form.

     

    3) Add a binding source (bsNorthwind) referencing the dataset.

     

    4) Add a grid using the binding source as its datasource.

     

    5) Add a button to the form with a click handler

     

    private void btnAddRow_Click(object sender, EventArgs e)
    {
      Object o = bsNorthwind.AddNew();
      DataSet1.CategoriesRow categoryRow = ((DataRowView)o).Row as DataSet1.CategoriesRow;
      categoryRow.CategoryName = "Fudge";
      categoryRow.Description = "Type of Fudge";
    }

     

    Because the row is added via the binding source and returned as as a reference, you probably will avoid the data index corruption problem.


     

     

    17 апреля 2008 г. 15:07
  •  

    I current use VS 2008 and i can reproduce this error, in my case in a datatable that contain a Key, I can walk arround eliminating the key but a hava another data table with other keys, and I dont want to loose fait in .Net, but this issue has more tha 1 year, first I install de hotfix, now I chaange to VS2008 and still the same problem

     

    good lock to all


  • thanks for the tip!  this worked well for me.  i was getting the index corrupted error when clicking on the delete item button on my bindingnavigator in my C# winform application.  in the event handler for the button click, I called openingsBindingSource.RemoveCurrent(); to remove the current record from the openings datatable.  this is the line of code that threw the exception. after placing openingsBindingSource.MoveFirst() and openingsBindingSource.MoveLast() before calling removecurrent, the index corrupted exception is no longer thrown. rebuilding the index = great idea, thanks again!

  • We have the same issue (corrupted index error 5) already described before.

    We have a DataSet binded to a UltraGrid (Infragistics). DataViews are created by Infragistics component. When the user has a sort and filter setting active on the grid (that should corresponds to an equivalent DataView), *sometime* (once a day, in average) the user get the exception of corrupted index when the DataRow.EndEdit is called in the code that is loading a new record in the DataTable.

    We don't have multiple threads, and we don't have UI events occurring during the DataTable loading, which is the operation that generates the exception (even if not in a reproducable manner).

     

    We have already installed .NET 2.0 SP1.

     

    What is the current state of the issue? Are you working on it or is this issue "freezed" because you're not able to reproduce?

     

    Thanks.

     

    Marco Russo

    http://www.sqlbi.eu

    http://sqlblog.com/blogs/marco_russo

     

    2 июля 2008 г. 10:50
  • How are you adding the new row?  Is it being added through the grid? Is it being added by the binding source? Is it being added directly to the data table? 

     

    2 июля 2008 г. 13:10
  •  

    The row is created calling DataTable.NewRow(), then their fields are compiled and it is added to the Data Table and at last it is added to the DataTable calling DataTable.Rows.Add() method.

     

    Marco

    2 июля 2008 г. 13:34
  • Try adding the row to the binding source instead of the underlying data table.   For example:

     

    Assuming your grid is bound to bindingSource bsLeadership

     

    Datasets.DSLeadershipForm.LeadershipRow leadershipRow = bsLeadership.AddNew() as Datasets.DSLeadershipForm.LeadershipRow;

    leadershipRow becomes a pointer to which you can apply column values.

     

    This should eliminate your corrupted index problem.

     

     

    Jim

     

    2 июля 2008 г. 14:51
  •  

    It is not so easy. The DataSet contains three DataTables, which are nested in an UltraWinGrid component by Infragistics.

    The BindingSource.AddNew would add a record in the table that corresponds to the record type at the current position, but this is not what the code has to do.

     

    However, I think that this unstable behavior of DataTable should be addressed or at least documented by Microsoft...

     

    Marco

  • Here is some code that adds rows both to the header and detail of a master/detail bound grid.

     

    private void btnParse_Click(object sender, EventArgs e)
    {
      string[] lines = memoEdit.Text.Split(new char[] { '\n' });
      if (lines.Length > 8)
      {
        // bsWeb is bound to the dataset dsWeb with the data member set to WebHdr
        Datasets.DSWeb.WebHdrRow hdrRow = (Datasets.DSWeb.WebHdrRow)((DataRowView)bsWeb.AddNew()).Row;
        bsWeb.EndEdit();
        int index = bsWeb.Find("WebHdrID", hdrRow.WebHdrID);
        bsWeb.Position = index;
        for (int i = 0; i < lines.Length; i++)
        {
          string[] words = linesIdea.Trim().Split(new char[] { ' ' });
          if (words.Length >= 2)
          {
            // bsDetail is bound to bsWeb with the data member set to the relationship to between the header and detail
            Datasets.DSWeb.WebDtlRow dtlRow = (Datasets.DSWeb.WebDtlRow)((DataRowView)bsDetail.AddNew()).Row;
            dtlRow.FieldName = words[0];
            string fieldValue = words[1];
            for (int j = 2; j < words.Length; j++)
            {
              fieldValue += " " + words[j];
            }
            dtlRow.FieldValue = fieldValue.Trim();
            bsDetail.EndEdit();

            if (dtlRow.FieldName == "Fullname")
            {
              hdrRow.CompanyName = dtlRow.FieldValue;
              bsWeb.EndEdit();

            }

          }
         }
        }
        memoEdit.Text = null;
      }
    }

    23 июля 2008 г. 12:42
  • I read the entire discussion and went to the following link:
    which seems to apply to my problem;
    in this page there is another link supoosed to direct me to the download page for the hotfix, the link is:
    but this points to a page which title is: KB932491 Unable to auto-attach to ASP.Net applications 
    the issue title found on this page is: KB932491 FIX: Unable to auto-attach to ASP.Net applications on Windows Vista Home Edition
    and when I download and run the fix it tells me that I have not the correct software installed on my machine.

    My qestion is: where can I find the correct hotfix to download?

    thanks
    Stefano


    17 сентября 2008 г. 17:01
  • I dug around using reflector on .NET 2.0 (post hotfix), I've found that a DataTable has a private ReaderWriterLock field. That field (Reflector calls it System.Data.DataTable.indexesLock) is used to make all internal System.Data.Index operations threadsafe -- except for in one very notable instance, the CreateIndex() call inside System.Data.Select.SelectRows(). Several method calls inside this use the lock point to grab a WriteLock on the indexes, however, nowhere inside of SelectRows() does it take a ReadLock. This means ThreadA could be in the middle of reading an index while ThreadB is creating one, since the WriteLock will be granted due to no current ReadLocks.

    I think System.Data.Select.SelectRows() should be aquiring a ReadLock from the shared index locking point. For a few reasons:

    1) It sticks out as being inconsistent in relation to all other index operations. The others are all threadsafe but his one is not. It doesn't matter if DataSet and its children are supposed to be inherently threadsafe or not, somebody started something in there that did not get finished.

    2) It is completely unintuitive that DataTable.Select(...) is a potential WRITE operation on a DataTable. This is compounded by the fact that it is not listed in the documentation. The creation of an index to speed selection is a completely internal implementation feature of which we should not need be aware. Threadsafety was started in here but seemingly has a bug, so see #1.

    3) This will probably fix the index corruption issues for people doing concurrent Selects, though from the researched comments from others, I think they'll still be a few other issues (mainly with data binding) that this doesn't fix.

    4) For people wanting to use a DataTable shared between threads, they currently need to take an exclusive lock on the object just to Select from it. Yes there are workarounds, but there shouldn't need to be. Performance would be drastically increased if they could use ReaderWriterLocks of their own when sharing a DataTable. Many of them probably are already and just haven't hit this race condition.

    Thoughts?
    26 сентября 2008 г. 16:12
  • Hi,

    I am writing a very simple application yet had to struggle with the DataTable Internal Index is Corrupted problem for a couple of days. Now I had found a solution that I would like to share with others who are writing similarly simple applications.

    The Problem -

    In my application, I have a DataGridView that is bound at design-time to a Strongly Typed Dataset. I programmed the underlying TableAdapters to update the database from the underlying DataSet upon the DataGridView RowEnter event (doing this with the RowLeave event does not work) which fires when the user moves from one row to another. The same update is also programmed into the DataGridView Leave event which fires when the user moves from one form to another.


    This arrangement works for inserts and updates, but not deletes. There is a need to refresh the underlying dataset after deletes have been updated to the database, or the abovenamed error will occur.

    The Solution -

    The solution is to perform an update and a refreshing read of the underlying data into the DataSet in the DataGridView RowRemoved event.

    Complications -

    The solution gave rise to some complications, but these were easily removed.

    Firstly, the RowEnter and RowRemoved events fired during Form loading, and this caused problems as it was occuring in conjunction with the initial data loading process. The solution is to create a sentinel value at the form level which is set to True only upon Form Activated event. The update routine then checks for this value to be true before performing any update.

    Secondly, I continued to have problems in error handling for rows using databound Comboboxes. This was easily removed by creating another sentinel value at Form level which is set to True after the first time data is loaded into the combox. Data is not loaded into the combobox if on subsequent refreshes the sentinel value had already been set to true.

    Following is the code for a form with a databound DataGridView containing a databpund Combobox

    <CODE>
    Public Class ServicesFrm

        Private isInitiated As Boolean
        Private isComboInitiated As Boolean

        Private Sub ServicesFrm_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
            isInitiated = True
        End Sub

        Private Sub ServicesFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            readData()
        End Sub

        Private Sub ServicesFrm_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
            Me.DataGridView1.Top = 0
            Me.DataGridView1.Left = 0
            Me.DataGridView1.Width = Me.Width
            Me.DataGridView1.Height = Me.Height
        End Sub

        Private Sub saveData()
            Try
                Dim i As Integer = Me.LDRYServices_SP_getListTableAdapter.Update(Me.LaundryDS.LDRYServices_SP_getList)
            Catch e As Exception
                MsgBox(e.Message)
                readData()
            End Try
        End Sub

        Private Sub readData()
            Try
                If iscomboinitiated = False Then
                    Me.LDRYUOM_SP_getListTableAdapter.Fill(Me.LaundryDS.LDRYUOM_SP_getList)
                    isComboInitiated = True
                End If
                Me.LDRYServices_SP_getListTableAdapter.Fill(Me.LaundryDS.LDRYServices_SP_getList)
            Catch e As Exception
                MsgBox(e.Message)
            End Try
        End Sub

        Private Sub DataGridView1_RowEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowEnter
            saveData()
        End Sub

        Private Sub ServicesFrm_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Leave
            saveData()
        End Sub

        Private Sub DataGridView1_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles DataGridView1.DataError
            MsgBox(e.Exception.Message)
            readData()
        End Sub

        Private Sub DataGridView1_RowsRemoved(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsRemovedEventArgs) Handles DataGridView1.RowsRemoved
            If isInitiated Then
                saveData()
                readData()
            End If
        End Sub
    End Class

    </CODE>

    I will upload the unfinished application to http://coders.flameaters.com/laundry.zip for those who want to try and see how it works. The code was written using Visual Studio 2008 SP1 (but the behaviour was the same before SP1) and the database is SQL Server Express. Please take normal precautions to check the downloaded files for viruses etc as my hosted website is protected only with rudimentary security.

    Hope this will be helpful to the community.

    3 октября 2008 г. 4:29
  • hi,

    i am a beginner at VB.Net using VS2008 Express, 3.5 framework,  and am working on my very first windows application that uses a MS Access 2003 database, and i am getting this index error.  i notice that there has not been any more discussion on this topic since october 2008 and i was wondering if a solution has been figured out.  i have read this discussion in its entirety and have not yet tried the hotfix.  i am thinking it should have already been included in the version of visual studio that i have.

    if there is anyone still following this thread that might be able to point me in a direction to fix this problem, please reply.

    thank you,

    sherry
    I am using VS 2005 Express Edition
    13 января 2009 г. 18:42
  • I am using Visual Studio 2008 SP1, running against .NET 3.5 and have also been experiencing this error for quite some time, intermittently. The code that trips it for me is when I set the .Expression member on a DataColumn of a DataTable:

    DataColumn column = dtData.Columns[sColumnName]; 
    dtData.BeginLoadData(); 
    column.Expression = strPropValue; 
    dtData.EndLoadData(); 
     

    So despite the Begin/EndLoadData calls, setting column.Expression blows up from time to time. Not using multithreading, not calling ListingChanged or using BindingSources, nothing. As I understand it from reading this thread, a fix was supposed to make it into VS2008, but this apparently didn't remedy things. Would appreciate anyone's advice on how to fix this in my simple case.
    13 января 2009 г. 19:23
  • i tried the Begin/EndLoadData() approach too, with no success other than it changed the error type.  yesterday i was getting the error very consistently.  then this morning i added code to the Catch statement in the Try block to:

    1. refill the data table
    2. re-populate the new row from the textbox fields
    3. call AddNewRow() again on the data table
    4. show me a messagebox that says the first attempt had failed

    then proceeded with the rest of the code which first called the TableAdapter.Update(dataTable), and it had been accepting that.  several times it failed the first attempt, but succeeded at the second attempt.

    so then i moved my TableAdapter.Fill(dataTable) statement to the very beginning of the whole method.  (Previously i had statements to declare a new DataTableRow before the TableAdapter.Fill(DataTable).)   Since that change, it has not failed the first attempt to add a new row.

    sherry
    I am using VS 2005 Express Edition
    14 января 2009 г. 10:32
  • DataTable internal index is corrupted: '5' while changing combobox options :

    If you have 

    BindingSource.CurrentItemChanged Event loaded along with ComboBox.SelectedIndexChanged
    twice then that would cause the problem.

    Resolution :

    Unwire outer BindingSource.CurrentItemChanged
    Wire ComboBox.
    SelectionChangeCommitted

    nilesh gite

    4 февраля 2009 г. 0:48
  • I read the entire discussion and went to the following link:
    which seems to apply to my problem;
    in this page there is another link supoosed to direct me to the download page for the hotfix, the link is:
    but this points to a page which title is: KB932491 Unable to auto-attach to ASP.Net applications 
    the issue title found on this page is: KB932491 FIX: Unable to auto-attach to ASP.Net applications on Windows Vista Home Edition
    and when I download and run the fix it tells me that I have not the correct software installed on my machine.

    My qestion is: where can I find the correct hotfix to download?

    thanks
    Stefano



    I had done the exact same thing as Stefano and am receiving the same error.  I believe the specific error is:
    "The upgrade patch cannot be installed by the Windows Installer service because the program to be upgraded may be missing, or the upgrade patch may update a different version of the program.  Verify that the program to be upgraded exists on your computer and that you have the correct upgrade patch."

    The only idea we can come up with is that this hotfix is meant for Vista Home Edition only, whereas we have Enterprise Edition on our computers.

    Has anyone else run into this problem or know of a cause/fix?

    - Kevin
    10 июля 2009 г. 20:43
  • I have reviewed this with interest and may be able to propose a workaround that helps some people if they are still struggling.

    I have a binding navigator and it is bound to some text boxes - for the detail record and a data grid for the summary.

    I was using the CurrentChanged event to run a query. This would cause 2 items in the current record to be updated (an acknowledgement it has been viewed). This worked fine going forwards through the records with the next button on the navigator. However selecting a different record from the grid would seem to cause the error to be provoked.

    I considered the various work arounds (e.g. using the RowChanged event on the underlying table). Unfortunatley these were impractical, the row changed event was fired every time a row was added during initial population and thus this causes probolem, also after loading I would need to confirm the firsat one (and I couldn't figure out a way do finding the current record in a data table).

    However, my work around was to move the code to the Position event. When I did this all my problems went away.

    I also noticed another problem:-

    If the underlying data table was changed during the current changed event then the bound grid was NOT updated properly.

    No idea if this is helpful to anybody else, but I though it might be worth changing. Of course not being able to change the underlying table during a changed event is a major flaw, this must be a very common scenario.

    Regards,

    Simon.


    18 октября 2009 г. 9:53
  •  

        Hi, I have a problem with bindingsource component in framework 2.0.

    I have a combobox bound to a bindingsource which is also bound to a dataset with 2 related tables and a datagridview bound to the same bindingsource. What I want to do is : When the selectedindex property of my combobox changes, the corresponding cell value must be changed in the datagridview. But although the value in bindingsource changes, datagridview does not display the new value. That value is displayed after I move the mouse over that cell and make it invalidate its region manually.

    Another error I caught is the one that you can see as the subject of my post. I do not know why i have that message when I try to change the property of ((DataRowView)mybindingsource.Current)["MyProperty"] programmatically.

    I will be grateful if someone can help me.

     

    Hello, we had the same problem in our WinForm application in the similar situation. We added a new DataRow to our Dataset on the form and when selected index property of bounded combobox changed and then we tried to save our changes  - we caught this exception.   We check our DataSet settings and for DataColumn on which combobox was binding we set property 'AllowDBNull' = true. Our problem was resolved. 
    • Предложено в качестве ответа