Bug 57785 - DisplayAlert not processing when paging in IOS
Summary: DisplayAlert not processing when paging in IOS
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jimmy [MSFT]
Depends on:
Reported: 2017-06-27 09:20 UTC by david.staite
Modified: 2017-06-27 20:40 UTC (History)
2 users (show)

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

Example project (173 bytes, text/plain)
2017-06-27 09:39 UTC, david.staite

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 david.staite 2017-06-27 09:20:24 UTC
Ever since updating to visual studio 2017, Xamarin and Xamarin.Forms, IOS fails to display an alert when paging if the DisplayAlert function is in the main method of said new page, or in a method that is called from the page's main method.

Android works as expected.

I have replicated this by simply creating a new Xamarin.Forms project adding a new page, changing the layout to a navigation page in app.xaml.cs then using Navigation.PushAsync(new Page2()); in a button clicked event.

		public Page2 ()
			InitializeComponent ();
                        DisplayAlert("Alert","Welcome to Page 2!","OK");

Android shows the alert, IOS doesn't.

If I await the DisplayAlert, execution doesn't return back to the method.

A possible related issue is if I use Navigation.PopAsync(); in the main method I get (only in IOS):
Unhandled Exception:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

I would appreciate a response as I am trying to execute some code when paging, if it fails I want to display an alert then return back to the previous page.

I have attached my example.

Comment 1 david.staite 2017-06-27 09:39:30 UTC
Created attachment 23131 [details]
Example project
Comment 2 Jimmy [MSFT] 2017-06-27 20:40:55 UTC
Hi Dave, you can use Device.BeginInvokeOnMainThread() to ensure that DisplayAlert() is called on the main thread. This appears to resolve the issue when testing with the attached project:

Device.BeginInvokeOnMainThread(() =>
    DisplayAlert("Test", "Test Alert", "Okay");

Hope this helps!