Bug 18324 - [Compiler][Already fixed in Mono 3.2.7] Invalid IL code when calling method from within async delegate without await
Summary: [Compiler][Already fixed in Mono 3.2.7] Invalid IL code when calling method ...
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 4.12.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-03-12 14:15 UTC by Brendan Zagaeski (Xamarin Support)
Modified: 2014-03-13 04:12 UTC (History)
2 users (show)

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


Attachments
Test case (11.29 KB, application/zip)
2014-03-12 14:15 UTC, Brendan Zagaeski (Xamarin Support)
Details

Description Brendan Zagaeski (Xamarin Support) 2014-03-12 14:15:57 UTC
Created attachment 6294 [details]
Test case

Possible duplicates:
Bug #15527
Bug #13356


For this particular test case, the problem appears to be fixed on Mono 3.2.7 (currently on the Alpha channel).


## Steps to reproduce

1. Build and run the attached project using the Debug configuration in Xamarin Studio on Mac.

2. Click the "Hello World, Click Me!" button.


## Result.

> UNHANDLED EXCEPTION: System.InvalidProgramException: Invalid IL code in TestApp.MainActivity/<OnCreate>c__async0:MoveNext (): IL_0013: ldloc.1   
> 
> 
> at System.Runtime.CompilerServices.AsyncVoidMethodBuilder.Start<TestApp.MainActivity/<OnCreate>c__async0> (TestApp.MainActivity/<OnCreate>c__async0&) <IL 0x00022, 0x000bb>
> at TestApp.MainActivity.<OnCreate>m__0 (object,System.EventArgs) [0x00000] in /Volumes/ramdisk/TestApp/TestApp/MainActivity.cs:29
> at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000d] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/0deb0164/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Android.Views.View.cs:900
> at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.12-series/0deb0164/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Android.Views.View.cs:867
> at (wrapper dynamic-method) object.6e58b830-e440-4754-a730-4092cfad80d6 (intptr,intptr,intptr) <IL 0x00017, 0x00043>


## Workarounds

A. Remove the `async` keyword from the button.Click delegate.

OR

B. Change `Class1.DoSomeWork()` to an `async Task` method, and add `await` on the call to `class1.DoSomeWork()`

OR

C. Upgrade to Mono 3.2.7, then clean, and rebuild the solution.


## Version information

Tested on:
- Xamarin.Android 4.12.1
- Xamarin Studio 4.2.3 build 60
- Mono 3.2.6
- OS X 10.8.5

The problem does not happen when the project is built and run from Windows.
Comment 1 Sadik Ali 2014-03-13 03:42:23 UTC
I have checked this issue on below environments:

All MAC, Windows
XS 4.2.3 (Build 60)
XA: 4.12.1
Mono Mac 3.2.6

I followed steps mentioned  as in bug description and noticed that same exception is generated when click on Hello World, Click Me!" button.

Screen cast: http://screencast.com/t/aaZEQIR6
Exception log: https://gist.github.com/Sadik1/9523454
 
I check this on Window machine and not getting any exception. 

Also I check with Workarounds as mentioned in bug description and noticed that it is working

Note You need to log in before you can comment on or make changes to this bug.