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 ...
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.12.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2014-03-12 14:15 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2014-03-13 04:12 UTC (History)
2 users (show)

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

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

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 for Bug 18324 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Brendan Zagaeski (Xamarin Team, assistant) 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.


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


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