Bug 51502 - Picker.SelectIndex broken on XF.UWP when items loaded from a Async Task-result
Summary: Picker.SelectIndex broken on XF.UWP when items loaded from a Async Task-result
Status: RESOLVED DUPLICATE of bug 51642
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.4
Hardware: PC Windows
: --- blocker
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-01-13 11:51 UTC by Tom_Qv
Modified: 2017-02-15 18:56 UTC (History)
4 users (show)

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


Attachments
repro project (289.57 KB, application/zip)
2017-01-17 22:55 UTC, Jimmy [MSFT]
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 DUPLICATE of bug 51642

Description Tom_Qv 2017-01-13 11:51:56 UTC
# Steps to reproduce
List<string> myitems= await GetMyItemsAsync();
foreach (string item in myitems)
       picker.Items.Add(item );

# Expected behavior
just working....

# Actual behavior
System.ArgumentException occurred
  HResult=-2147024809
  Message=Value does not fall within the expected range.
  Source=Windows
  StackTrace:
       at Windows.UI.Xaml.Controls.Primitives.Selector.put_SelectedIndex(Int32 value)
       at Xamarin.Forms.Platform.UWP.PickerRenderer.UpdateSelectedIndex()
       at Xamarin.Forms.Platform.UWP.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.Element.OnPropertyChanged(String propertyName)
       at Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent)
       at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
       at Xamarin.Forms.BindableObject.SetValue(BindableProperty property, Object value, Boolean fromStyle, Boolean checkAccess)
       at Xamarin.Forms.Picker.set_SelectedIndex(Int32 value)
       at QvmXF.Helper.OptionPicker`1.set_SelectedItem(T value)
  InnerException: 


# Supplemental info (logs, images, videos)


# Test environment (full version information)
	  
this was working with 2.3.3, its a new bug with Forms.UWP 2.3.4
its also fine with Forms.Android and Forms.iOS
Comment 1 Tom_Qv 2017-01-13 16:41:34 UTC
correction: its also not working with Forms.Android anymore
didn't check iOs now, but Picker is messed up with 2.3.4 in combination with async.

going back to 2.3.3. everything is fine.
Comment 2 Jimmy [MSFT] 2017-01-17 22:55:33 UTC
Created attachment 19372 [details]
repro project

I believe I'm seeing the same issue described in comment 0 as I get the following stack trace: https://gist.github.com/jimmgarrido/6b4916bdc98f089180d5b1318a2ea268

However I think the real issue is that there are no items in the Picker which is why the exception is thrown when trying to set the SelectedIndex. Opening the Picker on UWP shows no items even though the debugger says that the Picker.Items is populated. I've attached a sample project that demonstrates this.

In the sample project the items are added to the picker in the page's OnAppearing() method. Interestingly though, the items _do_ appear if they are added in the constructor instead. If you add items in both areas, then only the ones from the constructor are visible. Also, the sample project does not use async/await so that might not be related to the issue as originally reported.


### Regression Status
This issue does _not_ happen with Forms 2.3.3.180 when the items are added in OnAppearing()


### Platforms Affected
I am only seeing this issue on UWP/WinRT unlike mentioned in comment 1. If the issue does exist in Android/iOS another project will need to be added reproduces the issue on those platforms.
Comment 3 Jimmy [MSFT] 2017-01-26 19:42:08 UTC
Possible duplicate of bug 51642

Bug 51642 is a separate report for the items not displaying in the Picker which seems to be cause of the crash in this report.
Comment 4 Samantha Houts [MSFT] 2017-02-15 18:56:38 UTC

*** This bug has been marked as a duplicate of bug 51642 ***