xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] Android CollectionView exception #8637

Closed stesvis closed 4 years ago

stesvis commented 5 years ago

Description

I get an exception when I use .Remove(item) on the ItemsSource of a CollectionView.

Steps to Reproduce

  1. Create a CollectionView and bind the ItemsSource to a ObservableCollection <CollectionView ItemsSource="{Binding Vehicles}">
  2. Programmatically remove an item from the collection Vehicles.Remove(vehicleToRemove);
  3. It throws the exception

Expected Behavior

Actual Behavior

System.ObjectDisposedException Message=Cannot access a disposed object. Object name: 'Xamarin.Forms.Platform.Android.GroupableItemsViewAdapter`2[[Xamarin.Forms.GroupableItemsView, Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null],[Xamarin.Forms.Platform.Android.IGroupableItemsViewSource, Xamarin.Forms.Platform.Android, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null]]'.

Basic Information

VladislavAntonyuk commented 5 years ago

https://github.com/xamarin/Xamarin.Forms/pull/8568 ?

stesvis commented 5 years ago

It still crashes on me like this: Device.BeginInvokeOnMainThread(() => Vehicles.Remove(vehicleToRemove));

samhouts commented 5 years ago

@stesvis Can you please attach a small project that demonstrates this issue? Thanks!

stesvis commented 5 years ago

Hello @samhouts can you try the one I have attached? After log in, go to the Inventory tab, click one of the camera icons and scan this barcode: pasted-image-0-1

levitica-organeyes-scanner-6536d4cb0ca4.zip

It crashes on:

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        // clear the list and only add the one found
                        InventoryItems.Clear();
                        InventoryItems.Add(item);
                    });
dblookup commented 4 years ago

Please try with version 4.3.0.991221 released two days ago. In my case, this solves the issue.

PureWeen commented 4 years ago

Can you let us know if what @dblookup says is correct @stesvis ?

Can you test this with the latest 4.4 pre and/or nightly? https://github.com/xamarin/Xamarin.Forms/wiki/Nightly-Builds

samhouts commented 4 years ago

@stesvis Since we haven't heard from you in more than 30 days, we hope this issue is no longer affecting you. If it is, please reopen this issue and provide the requested information so that we can look into it further. Thank you!