Bug 34185 - Invalid IL code in cycle 6 alpha
Summary: Invalid IL code in cycle 6 alpha
Status: RESOLVED NORESPONSE
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2015-09-22 17:50 UTC by Michael Teper
Modified: 2016-06-01 09:05 UTC (History)
5 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 GitHub or Developer Community 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 NORESPONSE

Description Michael Teper 2015-09-22 17:50:57 UTC
When I build my app with Cycle 6 beta 3 (Xam.Mac), my app crashes with:

Invalid IL code in XTractor.UI.ViewModels.GatherVisualContextTaskViewModel/<SetUpSimulatorLaunchCommand>c__AnonStorey31:<>m__1 (): IL_0003: stfld     0x04000391


System.InvalidProgramException: Invalid IL code in XTractor.UI.ViewModels.GatherVisualContextTaskViewModel/<SetUpSimulatorLaunchCommand>c__AnonStorey31:<>m__1 (): IL_0003: stfld     0x04000391


  at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x00012] in /private/tmp/source-mono-mac-4.2.0-branch/bockbuild-mono-4.2.0-pre2-branch/profiles/mono-mac-xamarin/build-root/mono-4.2.1/external/referencesource/mscorlib/system/threading/Tasks/Future.cs:686 
  at System.Threading.Tasks.Task.Execute () [0x00016] in /private/tmp/source-mono-mac-4.2.0-branch/bockbuild-mono-4.2.0-pre2-branch/profiles/mono-mac-xamarin/build-root/mono-4.2.1/external/referencesource/mscorlib/system/threading/Tasks/Task.cs:2523 
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () in /private/tmp/source-mono-mac-4.2.0-branch/bockbuild-mono-4.2.0-pre2-branch/profiles/mono-mac-xamarin/build-root/mono-4.2.1/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:line 143
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) in /private/tmp/source-mono-mac-4.2.0-branch/bockbuild-mono-4.2.0-pre2-branch/profiles/mono-mac-xamarin/build-root/mono-4.2.1/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:line 201
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) in /private/tmp/source-mono-mac-4.2.0-branch/bockbuild-mono-4.2.0-pre2-branch/profiles/mono-mac-xamarin/build-root/mono-4.2.1/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:line 170
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) in /private/tmp/source-mono-mac-4.2.0-branch/bockbuild-mono-4.2.0-pre2-branch/profiles/mono-mac-xamarin/build-root/mono-4.2.1/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:line 142
   at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () in /private/tmp/source-mono-mac-4.2.0-branch/bockbuild-mono-4.2.0-pre2-branch/profiles/mono-mac-xamarin/build-root/mono-4.2.1/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:line 372


Reverting back to beta channel resolves the crash.

My (alpha) info:
=== Xamarin Studio ===

Version 5.10 (build 799)
Installation UUID: ed6755aa-af00-4433-85c5-a4c5d023bc00
Runtime:
	Mono 4.2.1 (explicit/dbd6429)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010036

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.0 (8227)
Build 7A220

=== Xamarin.iOS ===

Not Installed

=== Xamarin.Mac ===

Version: 2.4.0.48 (Business Edition)

=== Xamarin.Android ===

Not Installed

=== Xamarin Android Player ===

Not Installed

=== Build Information ===

Release ID: 510000799
Git revision: 324ed342c08e2d35c4738f5cbb99f43d57186f90
Build date: 2015-09-18 14:43:35-04
Xamarin addins: 97a862a9dcaa31e9044c8613ef42e0a588c8d012
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.10.5
Darwin myellocos-Air 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 1 Chris Hamons 2015-09-23 09:26:35 UTC
So, it is likely we'll need an example to fix this, but first. Could you try keeping the current "working" packages and installing the latest Xamarin.Mac manually:

http://download.xamarin.com/XamarinforMac/Mac/xamarin.mac-2.4.0.48.pkg

That will tell us if it is Xamarin.Mac itself, or a bug (likely) in mono.
Comment 2 Michael Teper 2015-09-23 11:52:59 UTC
You're right, installing Xam.Mac 2.4.0.48 did not result in the the application crash. Does the stack trace provide any clues?
Comment 3 Chris Hamons 2015-09-23 12:03:37 UTC
Alright, so it is a bug in Mono most likely.

The stack just tells me "we're inside a thread task somewhat related to:

XTractor.UI.ViewModels.GatherVisualContextTaskViewModel/<SetUpSimulatorLaunchCommand>c__AnonStorey31

and we generated bad code, or something terrible happened."

Is there anyway I could get a repro case? The runtime team will be very interested in this bug. 

We can work through desk or mail it directly to me if that makes you feel more comfortable.
Comment 4 Michael Teper 2015-09-23 16:08:16 UTC
desk?
Comment 5 Chris Hamons 2015-09-23 16:21:57 UTC
Apologies. You could file a ticket at http://support.xamarin.com or mail me directly at chris.hamons@xamarin.com if you'd rather do that than attach a sample to the bug.
Comment 6 Michael Teper 2015-09-28 20:11:44 UTC
I dug a bit deeper into it today, and the problem was this bit of code:

Foo.Bar(async _ => await Task.Run(async () => 
{
  // ...
  await SomeMethod();
}));

If I simplify it to the following, I no longer get the bad IL exception:

Foo.Bar(async _ => 
{
  // ...
  await SomeMethod();
});
Comment 7 Michael Teper 2015-09-28 20:12:40 UTC
Oh, and btw, this issue is present in the newly released alpha 4 as well.
Comment 9 Chris Hamons 2015-09-29 09:18:43 UTC
This feels like a mono bug. Moving to mono.
Comment 10 Marek Safar 2015-10-05 05:56:23 UTC
I cannot reproduce your issue. Trying to follow your suggestion I came up with following repro

using System;
using System.Threading.Tasks;


class Foo
{
    public static void Bar (Func<Object, Task> t)
    {

    }
}


class C
{
    void Test ()
    {
        Foo.Bar(async _ => await Task.Run(async () => 
        {
          await SomeMethod();
        }));
    }

    async Task<int> SomeMethod ()
    {
        return 1;
    }

    public static void Main ()
    {
    }
}

but no error for me
Comment 11 Marek Safar 2016-06-01 09:05:30 UTC
No response