Bug 27101 - async/await behaviour changed after xamarin update
Summary: async/await behaviour changed after xamarin update
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 5.1
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2015-02-16 10:18 UTC by Jason
Modified: 2015-02-20 15:22 UTC (History)
2 users (show)

Tags:
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:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Jason 2015-02-16 10:18:41 UTC
I have a program which makes reasonable usage of async/await and worked up until last Thursday 10-Feb-2015.

Suddenly the entire app is crashing out from every option on the main menu, and awaits don't seem to be working as they did before. I've dissected an activity and ran it down to the following section of code:

public async override void OnAttachedToWindow ()
{
await RefreshList ();
GenerateMenu(); //Point C
base.OnAttachedToWindow ();
}
bool GenerateMenu()
{
bool output=false;
RootElement Root1=new RootElement("Productives");
//Root.Clear ();
Section section=null;

        List<string> employeesClockedOn=new List<string>();
        if (employees != null & employeesClockedOn != null)
        {
            string lastDepartment="kwyjibo";
            foreach (EmployeeListEmployee e in employees)
            {
                if (e.DepartmentDescription!=lastDepartment)
                {
                    if (section!=null)
                    {
                        Root1.Add (section);
                    }
                    section=InterfaceLayer.Section.NewSection(e.DepartmentDescription);
                    lastDepartment=e.DepartmentDescription;
                }
                SelectProductiveTableCell newElement=new SelectProductiveTableCell(e,employeesClockedOn.Contains(e.Name), UpdateMenu, SelectedEmployeeCallBack);
                section.Add(newElement);

            }
            employees=null;
            if (section!=null)
                Root1.Add(section);
            this.Root = Root1;
            output=true;
        }
        return output;
    }
    #region Refresh
    async Task<bool> RefreshList()
    {
        try
        {
            WorkingAlert working=new WorkingAlert();
            working.Context=this;
            await working.Show("Syncing Data, Please Wait.");    //Point A
            List<EmployeeListEmployee> newEmployees=await GetEmployeesAsync();   //Point B
            if (newEmployees==null)
            {
                await working.Hide();
                Intent intent=new Intent(this,typeof(YesNoAlert));
                intent.PutExtra("yes", "OK");
                intent.PutExtra("message", InterfaceLayer.SystemSettings.NetworkError);
                StartActivity(intent);
            }
            else
            {
                await working.Hide();
                this.employees=newEmployees;
            }
        }
        return false;
    }

What was happening before last Thursday was that at point A the system would await the showing of an alertdialog, then when the async call returned the program would continue processing at point B. Execution would continue through the RefreshList function, retrieving the data from the server, saving the data and regenerating the menu (or displaying an error and showing the previous info, if any is available).

From Thursday onwards, what is happening is that at point A the system would await the showing of an alertdialog, then when the async call returned the program would continue processing at point C - way up the call stack at OnAttachedToWindow, not as expected at point B. As a result, we attempt to generate the menu before we have any data (and possibly may never even attempt to retrieve data, as all the code from point B onwards is not run). My iOS version does not exhibit the same issues with awaits, when the awaited async call returns it returns back to the next line following the await.

Tried:
Clean/build app
Delete bin/obj folders
Delete app from device
Delete runtime from device
Uninstalling/Reinstalling Android SDK using Xamarins Installer
Reverting to previous versions of SDK-Tools

Jas.
Comment 1 Abhishek 2015-02-17 07:47:46 UTC
I have tried to reproduce this issue but unable to reproduce the reported behavior at my end.

Could you please provide the sample test app with the bug so that I can reproduce the reported behavior at our end?
Also provide the IDE Log, Android Device Log, Build Info and Application Output along with Exception.

IDE Log via Help-> Open Log Directory.
Android Device Log via->View-> Android Log.
Build Info:Xamarin Studio-> About Xamarin Studio-> Show Details. 

Build Info:

=== Xamarin Studio ===

Version 5.7.1 (build 17)
Installation UUID: 93e693b0-b53d-40f4-b29c-b61ff5cbe892
Runtime:
	Mono 3.12.0 ((detached/de2f33f)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000076

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.Mac ===

Version: 1.12.0.4 (Enterprise Edition)

=== Xamarin.Android ===

Version: 5.0.0.16 (Enterprise Edition)
Android SDK: /Users/xamarin23/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin.iOS ===

Version: 8.6.1.26 (Enterprise Edition)
Hash: 98ee412
Branch: 
Build date: 2015-02-11 04:37:05-0500

=== Build Information ===

Release ID: 507010017
Git revision: 0bc7d3550b6b088ac25b08dcf7bbe73bcc8658b3
Build date: 2015-02-03 19:43:29-05
Xamarin addins: f7b7d34419c9ec24501bfa7c658e80a6305613e0

=== Operating System ===

Mac OS X 10.10.0
Darwin 800BC.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 2 Jason 2015-02-17 08:46:33 UTC
I tried this morning to make a sample app but couldn't get the issue to replicate outside of the current project.

I've since found an issue elsewhere in my code - Type.GetEvents is returning 0 events on types known to have events, my code didn't trap for this - and it seems that is now causing an exception within many of the async events (it's in a pop-up dialog which is used in many places), and it's this exception that's causing it to jump about on its call stack a fair bit.

As it stands, I think this bug report should be closed, I'm pretty sure the bug as described is being caused by something else, and I'm looking into the something else.
Comment 3 Jonathan Pryor 2015-02-17 16:55:46 UTC
Closing as per comment #2.
Comment 4 Jonathan Pryor 2015-02-20 15:22:39 UTC
Closing as per comment #2.