Bug 14351 - Async/callbacks code generation bug
Summary: Async/callbacks code generation bug
Status: RESOLVED FIXED
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Mac OS
: --- major
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2013-08-30 14:38 UTC by Miguel de Icaza [MSFT]
Modified: 2013-09-01 08:49 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 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 FIXED

Description Miguel de Icaza [MSFT] 2013-08-30 14:38:07 UTC
This is a reduced test case that happens in some of our async support for iOS, and throws an ArgumentException from the compiler generated code when some of the captured variables are accessed:

using System.Threading.Tasks;
using System.Threading;
using System;

class X {
	static void Main ()
	{
		var x = new X ();
		x.Run ();
		Thread.Sleep (6000);
	}

	Task<int> AnimateAsync (Action callback)
	{
		callback ();
		return null;
	}

	void SecondLevel (Action callback)
	{
		callback ();
	}
	
	async void Run ()
	{
		var ret = await AnimateAsync (() => {
			SecondLevel (() => {
				// This throws System.ArgumentException: Value does not fall within the expected range.
				Console.WriteLine (this);
				});
		});
	}
}
Comment 1 Miguel de Icaza [MSFT] 2013-08-30 15:48:28 UTC
This sample, should throw a NullReferenceException when ran (that is what CSC compiled output does).   The reason it throws is because I took a lot of code out to make the test case simpler (the return null from task).

But Mono's C# compiler output raises an ArgumentException when running on Mono and raises a FatalExecutionEngine error on Windows (error code 0xc0000005) and is described as "This error may be a bug in the CLR or in the unsafe or non-code verifiable portiions of user code.   Common sources of this ug include user marshaling errors for COM-interop or PImvoke which may corrupt the stack"
Comment 2 Marek Safar 2013-09-01 08:49:25 UTC
Fixed in master