Bug 25165 - Bad code and async/await in a Task causes "Internal compiler error"
Summary: Bad code and async/await in a Task causes "Internal compiler error"
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2014-12-08 16:57 UTC by Adam Patridge
Modified: 2014-12-10 09:08 UTC (History)
1 user (show)

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:

Description Adam Patridge 2014-12-08 16:57:09 UTC
As I convert some legacy code to async/await and Tasks within some existing cruft, I ran into this error. It appears that an error my code is causing an "Internal compiler error" instead of revealing the actual build error I need to address.

    .../Program.cs(28,28): Error CS0584: Internal compiler error: Object reference not set to an instance of an object (CS0584) (SomeApp)

In the IDE, the hidden code error is indeed highlighted in red, so Source Analysis appears to be catching it correctly.

Here is a console app that recreates the issue.

	class MainClass
		public static void Main (string[] args)
			Console.WriteLine ("Hello World!");

			Task<Something> getSomething = (new TaskCompletionSource<Something> ()).Task;

			Task.Run (async () => {
				var something = await getSomething;
				if (something == null) {  // <-- "Internal compiler error"

				Console.WriteLine(something.Id); // <-- should be a build error instead (Id inaccessible)
	public class Something
		string Id { get; set; }

Commenting out that line removes the true build error, and it no longer has the internal compiler error.

	Task.Run (async () => {
		var something = await getSomething;
		if (something == null) { // <-- gets past here since build error is gone

Also, making the Task.Run Action synchronously will also remove the internal compiler error and reveal the true build error.

	Task.Run (() => {
		var something = new Something();
		if (something == null) {

		Console.WriteLine(something.Id); // <-- build error

Possibly related, though it seemed to affect an older version of Mono than I am using: https://bugzilla.xamarin.com/show_bug.cgi?id=22892

Xamarin Studio details:

> Xamarin Studio
> Version 5.5.4 (build 15)
> Installation UUID: 6fcde369-8230-488d-b74f-2c9b163b5a2f
> Runtime:
> 	Mono 3.10.0 ((detached/92c4884)
> 	GTK+ 2.24.23 (Raleigh theme)
> 	Package version: 310000031
Comment 1 Marek Safar 2014-12-10 09:08:19 UTC
Fixed in master