Bug 38717 - ObservableCollection.Clear() causes NullReferenceException on UWP
Summary: ObservableCollection.Clear() causes NullReferenceException on UWP
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.0.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-02-12 16:00 UTC by Caan Mee
Modified: 2016-02-13 18:23 UTC (History)
0 users

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Caan Mee 2016-02-12 16:00:03 UTC
Using a ListView with an ItemSource bound to an ObservableCollection causes a crash of the application when calling:


 System.NullReferenceException Object reference not set to an instance of an object.

   at Xamarin.Forms.Platform.UWP.WindowsBasePlatformServices.get_IsInvokeRequired()
   at Xamarin.Forms.ListProxy.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Xamarin.Forms.ListProxy.WeakNotifyProxy.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.ClearItems()
   at System.Collections.ObjectModel.Collection`1.Clear()
   at MyApp.MyViewModel.ResetList(IEnumerable`1 res)

Using latest Xamarin.Forms 2.1.0-pre4
Comment 1 Caan Mee 2016-02-13 18:23:16 UTC
This is solved when calling .Reset() on UI thread. Don't know why on uwp this stuff breaks (Android/iOS) working fine though without invoke on main thread.