Unplanned
Last Updated: 01 Dec 2022 16:12 by Simon
Simon
Created on: 24 Nov 2022 15:22
Category: UI for WPF
Type: Feature Request
0
RadDataPager: Disposes its Bound Source collection

Hi,

we are using our own IPagedCollectionView implementation in combination with the RadDataPager control as shown in the attached example project. Basically, we bind an instance of the PagedCollectionView that is provided by our ViewModel to the Source property of the RadDataPager.

Recently we started to take implementing the Dispose pattern a bot more seriously and also added the IDisposable interface to our custom PagedCollectionView (in order to Dispose some internally used CancellationTokenSource).  Today we realized that the RadDataPager now calls Dispose() on the PagedCollectionView  instance although not being its owner. This happens as soon as the DataPager itself is Disposed e.g. by switching modules (and thus loading a new DataTemplate) in our multi-module application. Coming back to the module will then cause the disposed Collection to be used again, potentially causing ObjectDisposedExceptions etc.

What I would expect: The RadDataPager control should not call Dispose() on its Source collection if it is Data-Bound to a ViewModel since that might leave the ViewModel in an invalid state that can cause Exceptions later on.

The problem exists with .net 6 and .net Framework 4.8 as well as with versions 2022.3.1109 (Xaml, see Example project) and 2022.2.621 (NoXaml)

 

Attached Files:
2 comments
Simon
Posted on: 01 Dec 2022 16:12

Hello Stenly,

thank you for your response! I am glad you consider implementing my proposal (I would probably still consider it a bug though since technically the View is destroying data that is owned by the ViewModel).

Unfortunately, the workaround you mentioned probably won't work for us since the custom PagedCollectionView in question actually performs queries against our database, returning an indeterminate, possibly infinite amount of elements. We implement IPagedCollectionView  to be able to selectively query pages of data and use the RadDataPager for means of navigation between pages. So simply replacing it with a ObservableCollection or some other memory-backed collection type is not possible in our case. However, we have - for now - worked around the issue by just not implementing IDisposable on the collection and instead disposing all disposable resources as soon as they are not needed anymore.

 

With kind regards
Simon Müller
Hofmann Fördertechnik GmbH

ADMIN
Stenly
Posted on: 01 Dec 2022 15:07

Hello Simon,

The reason for this behavior is that when binding an instance of this custom collection to the Source property of the RadDataPager control, internally, the control works with this instance. The internal Dispose method is called when the internal view model is being disposed of, which as result also calls the Dispose method in the custom collection.

Currently, the above statement is the default behavior of the control, however, it does seems like a good addition to its functionality, so I have converted this to a feature request instead of a bug report. For example, an option to prevent the internal code from not disposing of a collection that implements IPagedCollectionView when it is passed by the user. In addition, as a token of gratitude for bringing this to our attention, I have updated your Telerik points.

A possible workaround, for the time being, would be to pass a different type of collection that does not implement the IPagedCollectionView (for example an ObservableCollection). This is because internally the control will create a new QuearyableCollection instance, which implements the IPagedCollection interface and this collection will be disposed of when needed.

With this being said, I hope the provided information will be of help to you.

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.