Hi,I'm getting an exception from time to time in a grouped UltraWinGrid. The call stack is the followingSystem.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at Infragistics.Win.UltraWinGrid.UltraGridRow.get_ScrollCountInternal()
at Infragistics.Win.UltraWinGrid.UltraGridRow.Infragistics.Shared.ISparseArrayMultiItem.get_ScrollCount()
at Infragistics.Shared.SparseArray.EnsureScrollCountCalculatedHelper(NodeExtended n)
at Infragistics.Shared.SparseArray.EnsureScrollCountCalculated()
at Infragistics.Shared.SparseArray.GetVisibleCount()
at Infragistics.Win.UltraWinGrid.RowsCollection.GetVisibleRowCount(Boolean includeSpecialRows)
at Infragistics.Win.UltraWinGrid.RowsCollection.HasAnyVisibleRows()
at Infragistics.Win.UltraWinGrid.UltraGridGroupByRow.HasAnyVisibleChildRows()
at Infragistics.Win.UltraWinGrid.UltraGridGroupByRow.get_Hidden()
at Infragistics.Win.UltraWinGrid.UltraGridRow.get_HiddenInternal()
at Infragistics.Win.UltraWinGrid.UltraGridRow.get_HiddenResolved()
at Infragistics.Win.UltraWinGrid.RowScrollRegion.get_FirstRow()
at Infragistics.Win.UltraWinGrid.RowScrollRegion.GetMaxScrollPosition(Boolean scrollToFill)
at Infragistics.Win.UltraWinGrid.RowScrollRegion.EnsureScrollRegionFilled(Boolean calledFromRegenerateVisibleRows)
at Infragistics.Win.UltraWinGrid.RowScrollRegion.RegenerateVisibleRows(Boolean resetScrollInfo)
at Infragistics.Win.UltraWinGrid.RowScrollRegion.WillScrollbarBeShown(ScrollbarVisibility assumeColScrollbarsVisible)
at Infragistics.Win.UltraWinGrid.RowScrollRegion.PositionScrollbar(Boolean resetScrollInfo)
at Infragistics.Win.UltraWinGrid.ScrollRegionBase.SetOriginAndExtent(Int32 origin, Int32 extent)
at Infragistics.Win.UltraWinGrid.RowScrollRegion.SetOriginAndExtent(Int32 origin, Int32 extent)
at Infragistics.Win.UltraWinGrid.DataAreaUIElement.ResizeRowScrollRegions()
at Infragistics.Win.UltraWinGrid.DataAreaUIElement.PositionChildElements()
at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive)
at Infragistics.Win.UltraWinGrid.DataAreaUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive)
at Infragistics.Win.UltraWinGrid.DataAreaUIElement.set_Rect(Rectangle value)
at Infragistics.Win.UltraWinGrid.UltraGridUIElement.PositionChildElements()
at Infragistics.Win.UltraWinGrid.UltraGridUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive)
at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean clipText, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics)
at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize, Boolean preventAlphaBlendGraphics)
at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode)
at Infragistics.Win.UltraWinGrid.UltraGridUIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode)
at Infragistics.Win.UltraControlBase.OnPaint(PaintEventArgs pe)
at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.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)
This happens with version 9.2.20092.2017. Before we were running the same application with version 8.3.20083.1009 and never had this issue.
Looking at the source code this seems to be happening when adding a new cache item to the internal cache. Comparing this to the 8.3 version we see that all this caching thing is new.Something catched our eyes, though, in the source code. When looking at the usage of this cache in all other places we can see that it is used 4 times: in ScrollCountInternal, RowSpacingBeforeResolved, RowSpacingAfterResolved and BaseHeight. All but ScrollCountInternal use the following code// MBS 5/13/09 - TFS17523//cachedInfo.Add(this, rowInfo);cachedInfo[this] = rowInfo;
Only the ScrollCountInternal still uses the cachedInfo.Add(this, rowInfo) which finally raises the exception.May this be a bug you have seen before in the other three properties but missed to fix in the fourth? I'm sure that with cachedInfo[this] = rowInfo in ScrollCountInternal we would never get the above exception and thus red cross in our grid.
Thanks
Do you have the latest service release? This looks to me like a bug that was already fixed.
How to get the latest service release - Infragistics Community
Mike,
we are using 2009.2 SR 2017. However, we gave a look to the source code of SR 2035 and the property get_ScrollCountInternal() still has the code:
cachedInfo.Add(this, rowInfo);
rather than
cachedInfo[this] = rowInfo;
All other places (RowSpacingBeforeResolved(), RowSpacingAfterResolved() and baseHeight) have been fixed already.
Thanks,
Luis.
Hi,
I have this problem too with the version 9.2.20092.2090 .
It occurs (not everytime) when I load a layout with columns grouped by.
How could I resolve this problem ?
Are you sure it's exactly the same error?
The code in ScrollCountInternal was not changed, because there is no reason to change it - it is already checking to see if the item exists in the Dictionary before adding it.
Thank you for quick response.
I will try to refactor my code to avoid threading.
Have a nice day.
This is almost certainly a threading problem. You cannot use a BackgroundWorker thread to access or modify data that is bound to a control on the UI Thread. It is not possible to do this safely becuase you are not in control of the communication between the controls, the BindingManager, and the DataSource.
There is a detailed discussion of this here: Work with a dataset bound to a grid on a separate thread - Infragistics Community
In "newest" version of winforms (2013.1.2040) i am still getting this exception when grid contains about 19.000 rows.
Ps. I wrote custom search routine which sets "row.hidden = true/false" depending on search values. This method is working in BackgroundWorker. For small amount of data (let say < 2.000) it is working fine, but by more rows i am getting this exception.
Any chance to fix it or any workaround?
************** Ausnahmetext **************System.ArgumentException: Ein Element mit dem gleichen Schlüssel wurde bereits hinzugefügt. bei System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) bei System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) bei System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) bei Infragistics.Win.UltraWinGrid.UltraGridRow.get_ScrollCountInternal() bei Infragistics.Win.UltraWinGrid.UltraGridRow.Infragistics.Shared.ISparseArrayMultiItem.get_ScrollCount() bei Infragistics.Shared.SparseArray.EnsureScrollCountCalculatedHelper(NodeExtended n) bei Infragistics.Shared.SparseArray.EnsureScrollCountCalculatedHelper(NodeExtended n) bei Infragistics.Shared.SparseArray.EnsureScrollCountCalculatedHelper(NodeExtended n) bei Infragistics.Shared.SparseArray.EnsureScrollCountCalculatedHelper(NodeExtended n) bei Infragistics.Shared.SparseArray.EnsureScrollCountCalculatedHelper(NodeExtended n) bei Infragistics.Shared.SparseArray.EnsureScrollCountCalculatedHelper(NodeExtended n) bei Infragistics.Shared.SparseArray.EnsureScrollCountCalculatedHelper(NodeExtended n) bei Infragistics.Shared.SparseArray.EnsureScrollCountCalculated() bei Infragistics.Shared.SparseArray.GetVisibleCount() bei Infragistics.Shared.SparseArray.GetItemAtVisibleIndex(Int32 visibleIndex, ICreateItemCallback createItemCallback) bei Infragistics.Shared.SparseArray.GetItemAtVisibleIndexOffset(ISparseArrayMultiItem startItem, Int32 offset, ICreateItemCallback createItemCallback) bei Infragistics.Win.UltraWinGrid.ScrollCountManagerSparseArray.GetItemAtVisibleIndexOffset(UltraGridRow startRow, Int32 offset) bei Infragistics.Win.UltraWinGrid.RowsCollection.GetRowAtVisibleIndexOffset(UltraGridRow startAtRow, Int32 visibleIndexOffset, IncludeRowTypes includeRowTypes) bei Infragistics.Win.UltraWinGrid.RowsCollection.GetNextVisibleRow(UltraGridRow row, IncludeRowTypes includeRowTypes) bei Infragistics.Win.UltraWinGrid.RowsCollection.GetNextVisibleRow(UltraGridRow row) bei Infragistics.Win.UltraWinGrid.ViewStyleBase.AddSiblingRows(VisibleRowFetchRowContext& context, VisibleRow parentVisibleRow, UltraGridRow firstSibling) bei Infragistics.Win.UltraWinGrid.ViewStyleBase.RecreateRowList(RowScrollRegion rsr) bei Infragistics.Win.UltraWinGrid.RowScrollRegion.GetMaxScrollPosition(Boolean scrollToFill, Boolean ignoreScrollBoundsResolved) bei Infragistics.Win.UltraWinGrid.RowScrollRegion.GetMaxScrollPosition(Boolean scrollToFill) bei Infragistics.Win.UltraWinGrid.RowScrollRegion.EnsureScrollRegionFilled(Boolean calledFromRegenerateVisibleRows) bei Infragistics.Win.UltraWinGrid.RowScrollRegion.RegenerateVisibleRows(Boolean resetScrollInfo) bei Infragistics.Win.UltraWinGrid.RowScrollRegion.RegenerateVisibleRows() bei Infragistics.Win.UltraWinGrid.RowScrollRegion.WillScrollbarBeShown(ScrollbarVisibility assumeColScrollbarsVisible) bei Infragistics.Win.UltraWinGrid.ScrollRegionBase.WillScrollbarBeShown() bei Infragistics.Win.UltraWinGrid.RowScrollRegion.PositionScrollbar(Boolean resetScrollInfo) bei Infragistics.Win.UltraWinGrid.ScrollRegionBase.SetOriginAndExtent(Int32 origin, Int32 extent) bei Infragistics.Win.UltraWinGrid.RowScrollRegion.SetOriginAndExtent(Int32 origin, Int32 extent) bei Infragistics.Win.UltraWinGrid.DataAreaUIElement.ResizeRowScrollRegions() bei Infragistics.Win.UltraWinGrid.DataAreaUIElement.PositionChildElements() bei Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) bei Infragistics.Win.UltraWinGrid.DataAreaUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) bei Infragistics.Win.UltraWinGrid.DataAreaUIElement.set_Rect(Rectangle value) bei Infragistics.Win.UltraWinGrid.UltraGridUIElement.PositionChildElements() bei Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) bei Infragistics.Win.UltraWinGrid.UltraGridUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) bei Infragistics.Win.UIElement.VerifyChildElements(Boolean recursive) bei Infragistics.Win.ControlUIElementBase.VerifyIfElementsChanged(Boolean verify, Boolean syncMouseEntered) bei Infragistics.Win.ControlUIElementBase.get_CurrentCursor() bei Infragistics.Win.UltraControlBase.get_Cursor() bei System.Windows.Forms.Control.WmSetCursor(Message& m) bei System.Windows.Forms.Control.WndProc(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Hi mike and thank you for answering me.
I agree with you the code checks if the item already exists in the dictionary...but it seems that the item has been added in the interim (by another thread ?) and the exception is thrown.
Sébastien