Bug 22200 - picker's Items.Clear cause exception on WP
Summary: picker's Items.Clear cause exception on WP
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.2
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-08-19 07:47 UTC by bernhard.lang
Modified: 2014-09-23 19:20 UTC (History)
5 users (show)

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


Attachments
demo-project (76.31 KB, application/x-zip-compressed)
2014-08-19 07:47 UTC, bernhard.lang
Details


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:
Status:
RESOLVED FIXED

Description bernhard.lang 2014-08-19 07:47:14 UTC
Created attachment 7718 [details]
demo-project

When calling picker.Items.Clear() or when removing the last item from Items on WP an exception is thrown:

System.InvalidOperationException wurde nicht von Benutzercode behandelt.
  HResult=-2146233079
  Message=SelectedItem must always be set to a valid value.
  Source=Microsoft.Phone.Controls.Toolkit
  StackTrace:
       at Microsoft.Phone.Controls.ListPicker.OnSelectedItemChanged(Object oldValue, Object newValue)
       at Microsoft.Phone.Controls.ListPicker.OnSelectedItemChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
       at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
       at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
       at Microsoft.Phone.Controls.ListPicker.set_SelectedItem(Object value)
       at Microsoft.Phone.Controls.ListPicker.OnSelectedIndexChanged(Int32 oldValue, Int32 newValue)
       at Microsoft.Phone.Controls.ListPicker.OnSelectedIndexChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
       at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
       at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
       at Microsoft.Phone.Controls.ListPicker.set_SelectedIndex(Int32 value)
       at Microsoft.Phone.Controls.ListPicker.OnItemsChanged(NotifyCollectionChangedEventArgs e)
       at System.Windows.Controls.ItemsControl.OnItemCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
       at System.Windows.Controls.ItemCollection.NotifyCollectionChanged(NotifyCollectionChangedEventArgs e)
       at System.Windows.Controls.ItemCollection.UpdateItemsSourceList(IEnumerable newItemsSource)
       at System.Windows.Controls.ItemsControl.ItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
       at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
       at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
       at System.Windows.Controls.ItemsControl.set_ItemsSource(IEnumerable value)
       at Xamarin.Forms.Platform.WinPhone.PickerRenderer.UpdatePicker()
       at Xamarin.Forms.Platform.WinPhone.PickerRenderer.OnElementPropertyChanged(Object sender, PropertyChangedEventArgs e)
       at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)
       at Xamarin.Forms.BindableObject.OnPropertyChanged(String propertyName)
       at Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, Object value, Boolean currentlyApplying, Boolean clearBindings, Boolean raiseOnEqual)
       at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, Boolean clearBindings, Boolean raiseOnEqual, Boolean checkaccess)
       at Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object value, Boolean checkaccess)
       at Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object value)
       at Xamarin.Forms.Picker.set_SelectedIndex(Int32 value)
       at Xamarin.Forms.Picker.OnItemsCollectionChanged(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 bug_xamarin_picker.BuggyForm.button_Clicked(Object sender, EventArgs e)
       at Xamarin.Forms.Button.SendClicked()
       at Xamarin.Forms.Platform.WinPhone.ButtonRenderer.HandleButtonClick(Object sender, RoutedEventArgs e)
       at System.Windows.Controls.Primitives.ButtonBase.OnClick()
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
  InnerException: 




See attached demo-Project
Working on iOS and Android
reproduced in 1.2.2 and 1.2.3-pre1
Comment 2 bernhard.lang 2014-09-10 04:16:36 UTC
This issue is fixed in 1.2.3-pre2.
I don't change the status cause I don't know your Bug workflow.