Bug 44829 - Android.Speech.SpeechRecognizer: default IRecognitionListener native handle crash
Summary: Android.Speech.SpeechRecognizer: default IRecognitionListener native handle c...
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Android
Classification: Xamarin
Component: Linker ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Radek Doulik
URL:
Depends on:
Blocks:
 
Reported: 2016-09-28 15:04 UTC by Simon Chopin
Modified: 2017-08-23 20:33 UTC (History)
3 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 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:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Simon Chopin 2016-09-28 15:04:40 UTC
When using the SpeechRecognizer wrapper via the generated events instead of the SetRecognitionListener API, the system throws a System.NotSupportedException, but only after the subscribed events are triggered and processed. Using a custom Listener works around the issue.

Below are the exception, and the code.

Unhandled Exception:

System.NotSupportedException: Unable to activate instance of type Android.Speech.IRecognitionListenerImplementor from native handle 0xbef8eefc (key_handle 0x1ea36432).

09-28 16:25:00.549 D/Mono    (16059): [0xb7f39bd8] worker finishing
Thread finished: <Thread Pool> #5
Thread finished: <Thread Pool> #3
09-28 16:25:13.199 D/Mono    (16059): DllImport attempting to load: '/system/lib/liblog.so'.
09-28 16:25:13.199 D/Mono    (16059): DllImport loaded library '/system/lib/liblog.so'.
09-28 16:25:13.199 D/Mono    (16059): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
09-28 16:25:13.199 D/Mono    (16059): Searching for '__android_log_print'.
09-28 16:25:13.199 D/Mono    (16059): Probing '__android_log_print'.
09-28 16:25:13.199 D/Mono    (16059): Found as '__android_log_print'.
09-28 16:25:13.209 I/MonoDroid(16059): UNHANDLED EXCEPTION:
The thread 'Unknown' (0x5) has exited with code 0 (0x0).
The thread 'Unknown' (0x3) has exited with code 0 (0x0).
09-28 16:25:13.209 I/MonoDroid(16059): System.NotSupportedException: Unable to activate instance of type Android.Speech.IRecognitionListenerImplementor from native handle 0xbef8eefc (key_handle 0x1ea36432). ---> System.MissingMethodException: No constructor found for Android.Speech.IRecognitionListenerImplementor::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
09-28 16:25:13.209 I/MonoDroid(16059):    --- End of inner exception stack trace ---
09-28 16:25:13.209 I/MonoDroid(16059):   at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00039] in /Users/builder/data/lanes/3819/c1d1c79c/source/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:304 
09-28 16:25:13.209 I/MonoDroid(16059):   at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00138] in /Users/builder/data/lanes/3819/c1d1c79c/source/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:282 
09-28 16:25:13.209 I/MonoDroid(16059):    --- End of inner exception stack trace ---
09-28 16:25:13.209 I/MonoDroid(16059):   at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00186] in /Users/builder/data/lanes/3819/c1d1c79c/source/xamarin-android/src/Mono.Android/Java.Interop/TypeManager.cs:289 
09-28 16:25:13.209 I/MonoDroid(16059):   at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000e5] in /Users/builder/data/lanes/3819/c1d1c79c/source/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:459 
09-28 16:25:13.209 I/MonoDroid(16059):   at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x0001a] in /Users/builder/data/lanes/3819/c1d1c79c/source/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:430 
09-28 16:25:13.209 I/MonoDroid(16059):   at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in /Users/builder/data/lanes/3819/c1d1c79c/source/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:422 
09-28 16:25:13.209 I/MonoDroid(16059):   at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in /Users/builder/data/lanes/3819/c1d1c79c/source/xamarin-android/src/Mono.Android/Java.Lang/Object.cs:416 
09-28 16:25:13.209 I/MonoDroid(16059):   at Android.Speech.IRecognitionListenerInvoker.n_OnRmsChanged_F (System.IntPtr jnienv, System.IntPtr native__this, System.Single rmsdB) [0x00000] in /Users/builder/data/lanes/3819/c1d1c79c/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Android.Speech.IRecognitionListener.cs:330 
09-28 16:25:13.209 I/MonoDroid(16059):   at (wrapper dynamic-method) System.Object:868a6d74-be7a-4673-9047-782bca997b6c (intptr,intptr,single)
09-28 16:25:13.229 W/art     (16059): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable



The code using the API:


namespace XamarinFormsVocagenPOC.Droid
{
    class AndroidSpeechRecognizer : ISpeechRecognizer
    {
        private SpeechRecognizer recognizer;
        private TaskCompletionSource<IList<string>> currentCompletion;
        public AndroidSpeechRecognizer()
        {
            var ctx = Forms.Context;
            recognizer = SpeechRecognizer.CreateSpeechRecognizer(ctx);
        }

        public async Task<IList<string>> PerformRecognition()
        {
            currentCompletion = new TaskCompletionSource<IList<string>>();
            recognizer.Results += RecognizerResults;
            Intent intent = new Intent(RecognizerIntent.ActionRecognizeSpeech);
            intent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm);
            recognizer.StartListening(intent);
            var result = await currentCompletion.Task;
            currentCompletion = null;
            return result;
        }

        private void RecognizerResults(object sender, ResultsEventArgs e)
        {
            currentCompletion.SetResult(e.Results.GetStringArrayList(SpeechRecognizer.ResultsRecognition));
            recognizer.Results -= RecognizerResults;
        }
    }
}
Comment 1 Prashant [MSFT] 2017-07-03 08:51:49 UTC
Unfortunately, we’re unable to reproduce this report. If this issue is still occurring for you, please reopen this issue and attach a reproduction to the bug by starting with a clean Xamarin.Android project adding just the code necessary to demonstrate the issue.
Comment 2 Cody Beyer (MSFT) 2017-08-23 20:33:27 UTC
Unfortunately, we’re unable to reproduce this report. If this issue is still occurring for you, please reopen this issue and attach a reproduction to the bug by starting with a clean Xamarin.Android project adding just the code necessary to demonstrate the issue.