-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[CollectionView, Android] DisposedObjectException thrown when adding elements to ItemsSource after having disposed CollectionView containing EmptyView #6427
Comments
From the code it's because the ItemsViewAdapter is never disposed in the dispose method of the ItemsViewRenderer. I don't know if it's intended or not. |
Can you provide a sample with the issue please ? |
@jsuvanto Can you please attach a small project that demonstrates this issue? Thanks! |
I'm not sure if behaviour somehow depends on whether the EmptyView was specified in XAML or Code-behind. I haven't had the time to test this more thoroughly. I cannot provide a project just yet, but here's some excerpts of the code I used: Page.xaml:
MainViewModel.cs:
I'll try to provide a project that reproduces the behaviour as soon as I can. I hope these snippets help you meanwhile. |
@jsuvanto tried to make something out of your snippets together with your reproduction steps but I'm not quite sure what you're trying to do. See my (very ugly) code here. I got a bit confused with this bit:
You are trying to add something to a collection on a page that has been closed? I also see @kvpt already has some fix for (also) this in the making? |
@jfversluis My application has a main page with buttons that open a QR scanner and a device list page, which contains the CollectionView. Scanning a QR code adds a device to a list of devices, which serves as the CollectionView's item source. The device list page is opened with Navigation.PushAsync() and it is closed with Navigation.PopAsync(). If I open the device list page before any devices are added, return to main page and scan a QR code, the exception will be thrown. So yes, I am adding the new item to the item source while the page containing the CollectionView is not open. The QR scanner has been ruled out as the source of the problem. Using any method to add a new device to the item source should throw the exception. Unfortunately I am not authorised to publish the project where I first encountered this bug, since it is work-related code, and I haven't found myself the time to reproduce the bug. I appreciate your and @kvpt's help. If you have any more questions about this bug, please feel free to ask, and I will assist as much as I can. |
@jsuvanto I made a build from my fix branch Xamarin.Forms.4.1.0.zip |
@kvpt I confirm this package fixes the problem. The EmptyView string is displayed as expected and there is no exception thrown when adding an item to the ObservableCollection. |
@kvpt Sounds good! Thanks! (also, 4.1.0 is good!) |
@samhouts It's done. |
@samhouts Do you still need a reproduction? |
@jsuvanto No, I think we're good! If the stable version of 4.1.0 (to be released) doesn't resolve your issue, however, we may need you to reopen the issue. Thanks! |
Description
Adding elements to the ItemsSource of a CollectionView, that has EmptyView set, throws an exception. This exception cannot be caught calling the Add() function inside a try-catch. A workaround is not to set the EmptyView.
Steps to Reproduce
Expected Behavior
Element is added
Actual Behavior
An ObjectDisposedException is thrown:
Basic Information
The text was updated successfully, but these errors were encountered: