Bug 43182 - SFSpeechRecognizer.GetRecognitionTaskAsync() can trigger multiple callbacks (that cause exceptions)
Summary: SFSpeechRecognizer.GetRecognitionTaskAsync() can trigger multiple callbacks (...
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.99 (iOS 10 previews)
Hardware: PC Mac OS
: High major
Target Milestone: Xcode8 (iOS10)
Assignee: Alex Soto [MSFT]
Depends on:
Reported: 2016-08-08 20:08 UTC by Larry O'Brien
Modified: 2016-08-24 17:03 UTC (History)
3 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 Larry O'Brien 2016-08-08 20:08:13 UTC
`SFSpeechRecognizer.GetRecognitionTaskAsync(recognitionRequest)` is the async-ified version of the callback-ish `SFSpeechRecognizer.GetRecognitionTask(recognitionRequest, Action<SFSpeechRecognitionResult,NSError>)` but the callback handler is called ​*multiple*​ times as the speech recognizer refines things.

So, if one uses:

var recoResult = await speechRecognizer.GetRecognitionTaskAsync(recognitionRequest);
if (recoResult.BestTranscription != null) //...etc...

That runs fine *the first time* and then you get an exception, at least if you're running this via Task.Run(). I'm not sure if the async method is a mistake or if there's an iOS technique for manipulating the ExecutionContext that I don't know.
Comment 1 Sebastien Pouliot 2016-08-08 20:23:51 UTC
@Alex, please check other [Async]ified API, with Apple documentation, to see if other similar cases exists.
Comment 2 Alex Soto [MSFT] 2016-08-10 05:14:27 UTC
Patch: https://github.com/xamarin/xamarin-macios/pull/590
Comment 3 Alex Soto [MSFT] 2016-08-10 13:37:04 UTC
Fixed in xamarin-macios/xcode8 @ eedc7f618584c73cbdd0d558325af60232ae4504