Bug 39866

Summary: Await + finally produces exe that causes InvalidProgramException on Windows
Product: [Mono] Compilers Reporter: c
Component: C#Assignee: Marek Safar <masafa>
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: 4.0.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Tags: Is this bug a regression?: ---
Last known good build:

Description c 2016-03-23 14:59:55 UTC
A test case that can reproduce this is found at https://github.com/Unarmed/mono-invalidprogram

Building the supplied code on mono and then running it on Windows 8.1 x64 causes a crash. Exception details below.

To reproduce do:
mcs Program.cs

and reproduce crash with

If this is instead run with mono (as in "mono Program.exe") then the program will print the expected output "If you see this then everything is OK!" and exit cleanly. It will do so on all platforms as far as I can tell.

If I instead run the exe without mono (as in just "Program.exe") then at least on my Windows 8.1 x64 I instead see:
Unhandled Exception: System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at invalid_program.Program.<DoStuff>c__async0.MoveNext()
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine& stateMachine)
   at invalid_program.Program.DoStuff()
   at invalid_program.Program.Main(String[] args)

I have tried building with mono on windows and from the mono: docker image, both with the same results. 
I have not attempted to reproduce crash on more windows platforms.
I have .Net 4, 4.5 and 4.6 installed on the machine where the crash was found.
Rebuilding through Visual Studio 2015 produces an exe that can be run both with mono and without it.
Comment 1 Marek Safar 2016-04-09 07:51:43 UTC
Fixed in master