Bug 16036 - [btouch] Invalid code generated for async method
Summary: [btouch] Invalid code generated for async method
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: 7.0.4.x
Hardware: PC Mac OS
: --- normal
Target Milestone: 7.0.6
Assignee: Bugzilla
Depends on:
Reported: 2013-11-08 05:10 UTC by Alex Corrado [MSFT]
Modified: 2014-01-14 09:32 UTC (History)
4 users (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 Developer Community or GitHub 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 Alex Corrado [MSFT] 2013-11-08 05:10:50 UTC
btouch's async support generates invalid code in either of these cases:

a) There is no argument to the method except the callback
b) One of the arguments in the callback delegate is named "result"

For instance, this API definition:

using MonoTouch.Foundation;

namespace TestCase {

	delegate void TestHandler (int result, NSError err);

	[BaseType (typeof (NSObject))]
	interface Foo {

		[Async, Static, Export ("someMethod")]
		bool SomeMethod (TestHandler callback);

Generates this:

public unsafe static Task<int> SomeMethodAsync (, out bool result)
	var tcs = new TaskCompletionSource<int> ();
	result = SomeMethod((result, err) => {
		if (err != null)
			tcs.SetException (new NSErrorException(err));
			tcs.SetResult (result);
	return tcs.Task;

Note that even if not for the invalid comma at the beginning of the arg list, that method still wouldn't compile due to:

error CS0136: A local variable named `result' cannot be declared in this scope because it would give a different meaning to `result', which is already used in a `parent or current' scope to denote something else
Comment 1 Rolf Bjarne Kvinge [MSFT] 2013-11-08 19:07:06 UTC

maccore/master: 60f1a1aedc0404899fa028d5282bd1ad42e0528
monotouch/master: 5d8df6549378f815aec90561d2e68c586a5c64c5
Comment 2 PJ 2013-12-11 18:45:50 UTC
This fix is planned to be released with Xamarin.iOS 7.0.6, which should hit the beta channel before December 23rd.
Comment 3 Sadik Ali 2014-01-14 09:08:33 UTC
I have checked this following are the steps:

1. Created an iOS project and binding project.
2. Add above code in ApiDefinition.cs file of Binding project.
3. Debug application

But I am not sure how to check Generated code for the same.

Please suggest me if I am missing anything and how to check generated code?
Comment 4 Rolf Bjarne Kvinge [MSFT] 2014-01-14 09:26:53 UTC
Unit tests were added, there's no need for additional testing.
Comment 5 narayanp 2014-01-14 09:32:13 UTC
We are closing this issue because Unit test has been added for this.