This is a migrated thread and some comments may be shown as answers.

How to handle VirtualQueryableCollectionView exceptions?

12 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 1
Anton asked on 09 Oct 2018, 07:41 AM

 

I have a RadGridView that is bound to VQCV.

internal class TestContext : DbContext
{
    public DbSet<City> Cities { get; set; }
 
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);
 
        optionsBuilder.UseSqlite("Data Source=Test.db");
    }
}
 
internal class City
{
    public int Id { get; set; }
}
 
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    private VirtualQueryableCollectionView view;
 
    public MainWindow()
    {
        InitializeComponent();
        Load();
    }
 
    private void Load()
    {
        var context = new TestContext();
 
        if (File.Exists("Test.db"))
        {
            File.Delete("Test.db");
        }
 
        File.Copy(@"..\..\Test.db", "Test.db");
        view = new VirtualQueryableCollectionView(context.Cities);
        view.FilterDescriptors.Add(new FilterDescriptor("Id", FilterOperator.IsEqualTo, 123));
        GV.ItemsSource = view;
        File.Delete("Test.db");
    }

 

 

The view loads data from Entity Framework context. Sometimes it may throw DB exceptions, they go to the global level (dispatcher).

I don't know how to handle such exceptions.

private void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
    e.Handled = true;
}

See my test project: https://github.com/dermeister0/telerik-test

 

Run the app. Click on column sort icon. Resize window. Result - infinite loop of exceptions. RadGridView tries to measure itself, it gets count of records from VQCV, but the view throws exception.

 

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.Data.Sqlite.SqliteException: SQLite Error 1: 'no such table: Cities'.
   at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
   at Microsoft.Data.Sqlite.SqliteCommand.<PrepareAndEnumerateStatements>d__62.MoveNext()
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.ExecuteReader()
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
   at Microsoft.EntityFrameworkCore.Storage.Internal.NoopExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.GetResult[TResult](IEnumerable`1 valueBuffers, Boolean throwOnNullResult)
   at lambda_method(Closure )
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ResultEnumerable`1.GetEnumerator()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass15_1`1.<CompileQueryCore>b__0(QueryContext qc)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute(Expression expression)
   at Telerik.Windows.Data.QueryableExtensions.Count(IQueryable source)
   at Telerik.Windows.Data.VirtualQueryableCollectionView.get_ItemCount()
   at Telerik.Windows.Data.VirtualQueryableCollectionView.get_InternalCount()
   at Telerik.Windows.Data.QueryableCollectionView.get_IsEmpty()
   at Telerik.Windows.Data.DataItemCollection.get_IsEmpty()
   at Telerik.Windows.Controls.GridView.BaseItemsControl.OnItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Controls.DataControl.OnItemsCollectionChangedDispatch(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.DataItemCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.DataItemCollection.OnCollectionViewCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.Listener`2.ReceiveWeakEvent(Object sender, TArgs args)
   at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
   at Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.VirtualQueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.QueryableCollectionView.RefreshOverride()
   at Telerik.Windows.Data.QueryableCollectionView.RefreshOrDefer()
   at Telerik.Windows.Data.VirtualQueryableCollectionView.InvalidatePagingAndRefresh()
   at Telerik.Windows.Data.QueryableCollectionView.OnSortDescriptorsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadObservableCollection`1.RaiseCollectionChangedOnResume()
   at Telerik.Windows.Data.RadObservableCollection`1.ResumeNotifications()
   at Telerik.Windows.Data.CollectionHelper.Reset(IEnumerable source, IList target, Func`2 itemConverter)
   at Telerik.Windows.Data.ObservableCollectionManager.HandleCollectionChanged(IList sender, NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.ObservableCollectionManager.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadObservableCollection`1.RaiseCollectionChangedOnResume()
   at Telerik.Windows.Data.RadObservableCollection`1.ResumeNotifications()
   at Telerik.Windows.Controls.GridView.GridViewDataControl.PerformSorting(GridViewSortingEventArgs sortingArgs)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClassb7.<Sort>b__b6()
   at Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(FrameworkElement frameworkElement, Action action)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.Sort(GridViewColumn column, Boolean appendToExisting)
   at Telerik.Windows.Controls.GridView.GridViewHeaderCell.RequestSort(Boolean appendToExisting)
   at Telerik.Windows.Controls.GridView.GridViewHeaderCell.PerformUserSort()
   at Telerik.Windows.Controls.GridView.GridViewHeaderCell.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
   at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

12 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 11 Oct 2018, 01:53 PM
Hello Anton,

Thank you for the detailed report.

From the StackTrace it seems that the exception is raised from the framework when the Execute method of the IQueryProvider of the IQueryable source is called. For the time being I cannot relate this issue to RadGridView. The error from the StackTrace also shows that a table named Cities cannot be found. Can you please check this out?

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Anton
Top achievements
Rank 1
answered on 12 Oct 2018, 01:27 AM

Hi Stefan,

I know that Entity Framework throws the error, it's intentional. However, I need a way to handle such exceptions. Application should not crash.

 

The RadGridView causes infinite update loop and program hangs.

0
Stefan
Telerik team
answered on 16 Oct 2018, 03:23 PM
Hello Anton,

I am not completely sure I understand correctly. Can you please clarify what you mean by the error being raised intentionally? Also, is this exception raised if a similar setup is used with the standard MS DataGrid? I am not able to test this on my end as I cannot compile the project due to a lot of dependencies raising errors.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Anton
Top achievements
Rank 1
answered on 17 Oct 2018, 02:22 AM

Hi Stefan,

[quote]Can you please clarify what you mean by the error being raised intentionally?[/quote]

Sometimes data access level may return errors (timeout, database server unavailable). It's a normal situation. The test simulates a DB error.

[quote]Also, is this exception raised if a similar setup is used with the standard MS DataGrid?[/quote]

Yes, DataGrid has the same behavior when Telerik.Windows.Data.VirtualQueryableCollectionView is used. Application becomes completely unresponsive. However, it works fine with Telerik.Windows.Data.QueryableCollectionView.

[quote]I am not able to test this on my end as I cannot compile the project due to a lot of dependencies raising errors.[/quote]

It depends on .NET 4.6.1, Telerik.Windows.Controls, Telerik.Windows.Controls.GridView and Telerik.Windows.Data. All other libraries are loaded from NuGet.

I recorded a video.

https://imgur.com/Aqb6c85

0
Anton
Top achievements
Rank 1
answered on 17 Oct 2018, 02:29 AM

DataGrid example:

https://github.com/dermeister0/telerik-test/tree/data-grid

 

QueryableCollectionView example:

https://github.com/dermeister0/telerik-test/tree/qcv

0
Anton
Top achievements
Rank 1
answered on 17 Oct 2018, 02:30 AM

DataGrid example:

https://github.com/dermeister0/telerik-test/tree/data-grid

 

QueryableCollectionView example:

https://github.com/dermeister0/telerik-test/tree/qcv

0
Stefan
Telerik team
answered on 19 Oct 2018, 03:35 PM
Hello Anton,

Thank you for the update.

Strangely enough, when building the project with a VisualStudio older than the 2017 one the nuget package manager resolved the dependencies as expected. I have replicated the exception on my end as well. It seems, however, that it raised with a QueryableCollectionView source as well. I am now investigating what the cause for this might be, but I need a little more time for this. I will do my best to update you shortly.

Thank you for your understanding and cooperation.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Stefan
Telerik team
answered on 31 Oct 2018, 12:30 PM
Hello Anton,

Firstly, thank you very much for your patience.

I made a detailed research regarding this issue. Coming across this StackOverflow thread let us to the cause of the exception, which turned to be quite trivial. The SQLite raises an exception that the Table does not exist in the database as the database file is being deleted.
private void Load()
        {
            var context = new TestContext();
 
            if (File.Exists("Test.db"))
            {
                File.Delete("Test.db");
            }
 
            File.Copy(@"..\..\Test.db", "Test.db");
            view = new QueryableCollectionView(context.Cities);
            view.FilterDescriptors.Add(new FilterDescriptor("Id", FilterOperator.IsEqualTo, 123));
            GV.ItemsSource = view;
            
            File.Delete("Test.db");
        }

When this is avoided the control will work as expected.

I hope this helps.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Anton
Top achievements
Rank 1
answered on 31 Oct 2018, 02:28 PM

Hi Stefan,

Our real application stores SQLite database on a network share. Unfortunately, network connection interrupts sometimes.

We want to show "Database unavailable" error message to user and let him try again later.

However, the application hangs in infinite loop of queryable collection view. It becomes completely unresponsive.

Let me know if you need more details to clarify.

0
Stefan
Telerik team
answered on 05 Nov 2018, 11:54 AM
Hi Anton,

Can you please share some details regarding the infinite loop you refer to? I am able to reproduce the TargetInvocationException on my end, but I am not able to replicate such loop. As to handling the exception, the approach would not be different from handling exceptions in an IQueryable. You can take a look at this, this and this StackOverflow threads, for example.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Anton
Top achievements
Rank 1
answered on 07 Nov 2018, 03:26 PM

Hi Stefan,

 

> Can you please share some details regarding the infinite loop you refer to?

You can see it in the video:

https://imgur.com/Aqb6c85

Start app, apply filtering - one exception is thrown. Resize window - unstoppable series of exceptions starts.

> https://stackoverflow.com/questions/20623784/iqueryable-to-wrap-exceptions

This thread is interesting, thank you. I'll try to implement such behavior.


0
Stefan
Telerik team
answered on 12 Nov 2018, 12:42 PM
Hello Anton,

Thank you very much for the recorded video and for the clarification.

The exception is thrown as when the Window is being resized, a MeasureOverride is triggered. The count of the items is needed in this case so that the required calculations can be performed. I am afraid that I cannot suggest an approach for avoiding this as this is part of the core logic of the control.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Anton
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Anton
Top achievements
Rank 1
Share this question
or