Posted 21 January 2021, 6:19 pm EST
In the OnDemand Sample found at this path:
ComponentOne Samples\WPF.Net 5\CS\Grid\FlexGridExplorer\View\OnDemand.xaml
I am getting the following exception
Index was out of range. Must be non-negative and less than the size of the collection. (Parameter ‘index’)
at System.ThrowHelper.ThrowArgumentOutOfRange_IndexException() in /_/src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs:line 94
at System.Collections.Generic.List`1.get_Item(Int32 index) in /_/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/List.cs:line 150
at C1.DataCollection.C1CacheDataCollection`1.get_Item(Int32 index)
at C1.WPF.Grid.GridRowColCollection`1.get_Item(Int32 index)
at C1.WPF.Grid.FlexGrid.GetRow(GridCellType cellType, Int32 row)
at C1.WPF.Grid.GridCellFactory.UnbindCellContent(GridCellType cellType, GridCellRange range, FrameworkElement cellContent)
at C1.WPF.Grid.GridCellFactoryBase.UnbindCellContent(GridCellsPanelRange range, FrameworkElement cellContent)
at C1.WPF.Grid.GridCellsPanel.RecycleCell(CellHolder cellHolder)
at C1.WPF.Grid.GridCellsPanel.RecycleUnusedCells()
at C1.WPF.Grid.GridCellsPanel.GetIntrinsicContentSize()
at C1.WPF.Grid.GridCellsPanel.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) in /_/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/FrameworkElement.cs:line 4406
at System.Windows.UIElement.Measure(Size availableSize) in /_/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIElement.cs:line 656
at System.Windows.ContextLayoutManager.UpdateLayout() in /_/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/LayoutManager.cs:line 315
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg) in /_/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/LayoutManager.cs:line 582
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks() in /_/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs:line 1968
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) in /_/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs:line 1841
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget) in /_/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/MediaContext.cs:line 1744
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Threading/ExceptionWrapper.cs:line 103
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Threading/ExceptionWrapper.cs:line 36
at System.Windows.Threading.DispatcherOperation.InvokeImpl() in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs:line 540
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs:line 487
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj) in /_/src/Microsoft.DotNet.Wpf/src/shared/MS/Internal/CulturePreservingExecutionContext.cs:line 214
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:line 186
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 56
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ExecutionContext.cs:line 214
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) in /_/src/Microsoft.DotNet.Wpf/src/shared/MS/Internal/CulturePreservingExecutionContext.cs:line 172
at System.Windows.Threading.DispatcherOperation.Invoke() in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/DispatcherOperation.cs:line 409
at System.Windows.Threading.Dispatcher.ProcessQueue() in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs:line 2085
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs:line 2296
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in /_/src/Microsoft.DotNet.Wpf/src/shared/MS/Win32/HwndWrapper.cs:line 295
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) in /_/src/Microsoft.DotNet.Wpf/src/shared/MS/Win32/HwndSubclass.cs:line 429
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Threading/ExceptionWrapper.cs:line 103
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/Threading/ExceptionWrapper.cs:line 36
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs:line 1342
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) in /_/src/Microsoft.DotNet.Wpf/src/shared/MS/Win32/HwndSubclass.cs:line 378
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs:line 2135
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs:line 328
at System.Windows.Threading.Dispatcher.Run() in /_/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs:line 296
at System.Windows.Application.RunDispatcher(Object ignore) in /_/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs:line 2404
at System.Windows.Application.RunInternal(Window window) in /_/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs:line 1686
at System.Windows.Application.Run() in /_/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Application.cs:line 198
at FlexGridExplorer.App.Main()
I have made the following changes to get this exception
In the constructur of YouTubeCollectionView I added this line
_q = ".Net5";
In LoadVideosAsync I have replaced the existing code with this:
public static async Task<Tuple<string, IReadOnlyList<YouTubeVideo>>> LoadVideosAsync(string q, string orderBy, string pageToken, int maxResults, CancellationToken cancellationToken = default(CancellationToken))
{
if (q == null) q = "";
return new Tuple<string, IReadOnlyList<YouTubeVideo>>(pageToken, Enumerable.Range(0, maxResults).Select(x => new YouTubeVideo()
{
ChannelTitle = "Foo",
Description = "Foo",
Link = "Foo",
Thumbnail = "Foo",
Title = "Foo,"
}).ToList());
}
In OnDemand.xaml.cs I have increased the PageSize to 1000
_dataCollection = new YouTubeCollectionView() { PageSize = 1000 };
In OnDemand.xaml.cs I have commented out the search in constructor
//search.Text = ".Net5";
//var task = PerformSearch();
In OnDemand.xaml I have changed the flexGrid to AutoGenerateColumns
<c1:FlexGrid x:Name="grid" AutoGenerateColumns="True" HeadersVisibility="Column" IsReadOnly="True" Grid.Row="1">
<!--<c1:FlexGrid.Columns>
<c1:GridImageColumn Binding="Thumbnail" Header=" " Width="62" PlaceHolder="/FlexGridExplorer;component/Images/default.png"/>
<c1:GridHyperlinkColumn Binding="Link" ContentBinding="Title" Header="Title" TargetName="_blank" MinWidth="300" Width="*"/>
<c1:GridColumn Binding="ChannelTitle" Header="Channel"/>
</c1:FlexGrid.Columns>-->
<e:Interaction.Behaviors>
<c1:EmptyGridBehavior EmptyView="{Binding ElementName=emptyListLabel}" />
</e:Interaction.Behaviors>
</c1:FlexGrid>
To get the error all I have to do is open the OnDemand demo and try to scroll.
You may also get the exception without scrolling right after opening the demo.
Notice, that the following changes introduces a couple of glitches.
- The UI won’t have all the rows loaded on start and the may only appear after scrolling a bit
- The first cell [0,0] wont be displayed at all, sometimes instead of the blank there will be a loading circle visible
- The above exception, may come after some pages have already been loaded when the GetPageAsync method finishes to fast, adding this code seems to help
await Task.Delay(100);
- If you manage to scroll without the crash, loading a second page seems to fail when you work with a pageToken of null, I could fix this by adding a Guid.NewGuid as a pageToken, like this
public static async Task<Tuple<string, IReadOnlyList<YouTubeVideo>>> LoadVideosAsync(string q, string orderBy, string pageToken, int maxResults, CancellationToken cancellationToken = default(CancellationToken))
{
if (q == null) q = "";
return new Tuple<string, IReadOnlyList<YouTubeVideo>>(Guid.NewGuid().ToString("D"), Enumerable.Range(0, maxResults).Select(x => new YouTubeVideo()
{
ChannelTitle = "Foo",
Description = "Foo",
Link = "Foo",
Thumbnail = "Foo",
Title = "Foo,"
}).ToList());
}
I have attached the changed files.
OnDemand.zip