Hi, I have an application where a bunch of records can be selected by the user and an action performed on them. In some cases, for some of our users, when they apply an operation that involves getting the selected items, the below exception is thrown.
In our method that gets the currently selected data records, we have some logic that makes sure the data records are of specific type, and not any of the special records, like group headers, etc...
Once the action is applied, the data types of the selected data records are updated almost immediately by a backend service.
To the user it's a very simple operation. Select some rows, right-click, select an action from a context menu, some server-side transaction takes place, and the selected fields are updated on their screen with the results.
Seems like the exception is thrown right after the update. Which means that the selected items were indeed selected, but when updated, something goes wrong. It's not reproducible all of the time.
What can cause this exception?
Unhandled exception: System.IndexOutOfRangeException: Index was outside the bounds of the array. at Infragistics.Collections.SparseArray.ValidateIndex(Int32 index) at Infragistics.Collections.SparseArray.GetItem(Int32 index, ICreateItemCallback createItemCallback) at Infragistics.Windows.DataPresenter.FlatScrollRecordsCollection.get_Item(Int32 index) at Infragistics.Windows.DataPresenter.FlatScrollRecordsCollection.EnsureItemsAllocated(Int32 startIndex, Int32 count) at Infragistics.Windows.DataPresenter.FlatScrollRecordsCollection.BeginMeasure(GenerationCache generatorCache) at Infragistics.Windows.DataPresenter.GridViewPanelFlat.GenerationCache..ctor(GridViewPanelFlat panel, Boolean isVertical, Size constraint, Int32 overallScrollPosition, ScrollDirection scrollDirection) at Infragistics.Windows.DataPresenter.GridViewPanelFlat.MeasureOverride(Size availableSize) at System.Windows.FrameworkElement.MeasureCore(Size availableSize) at System.Windows.UIElement.Measure(Size availableSize) at System.Windows.ContextLayoutManager.UpdateLayout() at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg) at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork() at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) at System.Threading.ExecutionContext.runTryCode(Object userData) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(ApplicationContext context)
Did you get a solution for this issue? I also have same problem on ValidateIndex.
Thanks Stefan!
I think the problem is thread related. In my code I was updating from a background thread incorrectly, which I believe may have caused this problem, but not entirely sure.
Hello,
I have created a sample project for you where I added a ContextMenu to the XamDataGrid and when I click on the Menu’s Item a MessageBox shows the SelectedRecords’ Count. If the sample doesn’t satisfies all your needs feel free to modify it, so it reproduces your behavior and send it back to me for further investigation.
Looking forward for your reply.
The stack trace is pretty clear in stating there is an index out of range, which means that some collection is being modified somewhere and something is not there. I don't have your products source code, so I cannot go in there and find out what happened. I can tell you that the error is thrown on the main GUI thread.
Yes, this is an issue that I cannot debug, and is still occurring. Can you let me know what can cause this so I can look into a specific scenario where I can reproduce this reliably?