Bug 27408

Summary: SynchronizationContext Post() crash
Product: Android Reporter: Mikalai <nikolaiy>
Component: Mono runtime / AOT CompilerAssignee: Jonathan Pryor <jonp>
Status: VERIFIED FIXED    
Severity: critical CC: adrianknight89, agudim, andy, cgbugzilla, daveoc64, david, glenn.wester, jean-marie.gueirard, Kent.Green, kevin.wong, kpbugzilla, livelox, matt, miguel, miha, mikhail.melnik, mohitk, mono-bugs+monodroid, niraz, peter.collins, raximusek, samkevich, schiller, steve, yann.robin
Priority: High    
Version: 5.0   
Target Milestone: 5.1   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Test sample
adb logcat output
adb log

Description Mikalai 2015-02-25 09:02:08 UTC
Created attachment 10026 [details]
Test sample

Sample app crashes on _some_ devices with Android 5:

Samsung GT-I9500 Galaxy S IV (Android 5.0.1)
Samsung SM-N900 Galaxy Note 3 (Android 5.0)

Exception info:
[Timeline] Timeline: Activity_idle id: android.os.BinderProxy@384df149 time:60149202
[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.NotSupportedException: Unable to activate instance of type Java.Lang.Thread+RunnableImplementor from native handle be9ea02c ---> System.MissingMethodException: No constructor found for Java.Lang.Thread+RunnableImplementor::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
[MonoDroid] Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
[MonoDroid]   --- End of managed exception stack trace ---
[MonoDroid] java.lang.Error: Java callstack:
[MonoDroid] 	at mono.java.lang.RunnableImplementor.n_run(Native Method)
[MonoDroid] 	at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
[MonoDroid] 	at android.os.Handler.handleCallback(Handler.java:739)
[MonoDroid] 	at android.os.Handler.dispatchMessage(Handler.java:95)
[MonoDroid] 	at android.os.Looper.loop(Looper.java:145)
[MonoDroid] 	at android.app.ActivityThread.main(ActivityThread.java:5944)
[MonoDroid] 	at java.lang.reflect.Method.invoke(Native Method)
[MonoDroid] 	at java.lang.reflect.Method.invoke(Method.java:372)
[MonoDroid] 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
[MonoDroid] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
[MonoDroid]   --- End of inner exception stack trace ---
[MonoDroid]   at Java.Interop.TypeManager.CreateProxy (System.Type type, IntPtr handle, JniHandleOwnership transfer) [0x00000] in <filename unknown>:0 
[MonoDroid]   at Java.Interop.TypeManager.CreateInstance (IntPtr handle, JniHandleOwnership transfer, System.Type targetType) [0x00000] in <filename unknown>:0 
[MonoDroid]   --- End of inner exception stack trace ---
[MonoDroid] at Java.Interop.TypeManager.CreateInstance (intptr,Android.Runtime.JniHandleOwnership,System.Type) <0x006e4>
[MonoDroid] at Java.Lang.Object.GetObject (intptr,Android.Runtime.JniHandleOwnership,System.Type) <0x00277>
[MonoDroid] at Java.Lang.Object._GetObject<Java.Lang.IRunnable> (intptr,Android.Runtime.JniHandleOwnership) <0x0004f>
[MonoDroid] at Java.Lang.Object.GetObject<Java.Lang.IRunnable> (intptr,Android.Runtime.JniHandleOwnership) <0x0002b>
[MonoDroid] at Java.Lang.Object.GetObject<Java.Lang.IRunnable> (intptr,intptr,Android.Runtime.JniHandleOwnership) <0x00037>
[MonoDroid] at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) <0x00027>
[MonoDroid] at (wrapper dynamic-method) object.f47b3182-2f06-419f-97f3-4b389b007bb9 (intptr,intptr) <0x0003b>
[art] JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
[mono] 
[mono] Unhandled Exception:
[mono] System.NotSupportedException: Unable to activate instance of type Java.Lang.Thread+RunnableImplementor from native handle be9ea02c ---> System.MissingMethodException: No constructor found for Java.Lang.Thread+RunnableImplementor::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
[mono] Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
[mono] 
[mono]   --- End of managed exception stack trace ---
[mono] java.lang.Error: Java callstack:
[mono] 	at mono.java.lang.RunnableImplementor.n_run(Native Method)
[mono] 	at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
[mono] 	at android.os.Handler.handleCallback(Handler.java:739)
[mono] 	at android.os.Handler.dispatchMessage(Handler.java:95)
[mono] 	at android.os.Looper.loop(Looper.java:145)
[mono] 	at android.app.ActivityThread.main(ActivityThread.java:5944)
[mono] 	at java.lang.reflect.Method.invoke(Native Method)
[mono] 	at java.lang.reflect.Method.invoke(Method.java:372)
[mono] 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
[mono] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
[mono] 
[mono]   --- End of inner exception stack trace ---
[mono]   at Java.Interop.TypeManager.CreateProxy (System.Type type, IntPtr handle, JniHandleOwnership transfer) [0x00000] in <filename unknown>:0 
[mono]   at Java.Interop.TypeManager.CreateInstance (IntPtr handle, JniHandleOwnership transfer, System.Type targetType) [0x00000] in <filename unknown>:0 
[mono]   --- End of inner exception stack trace ---
[mono]   at Java.Interop.TypeManager.CreateInstance (IntPtr handle, JniHandleOwnership transfer, System.Type targetType) [0x00000] in <filename unknown>:0 
[mono]   at Java.Lang.Object.GetObject (IntPtr handle, JniHandleOwnership transfer, System.Type type) [0x00000] in <filename unknown>:0 
[mono]   at Java.Lang.Object._GetObject[IRunnable] (IntPtr handle, JniHandleOwnership transfer) [0x00000] in <filename unknown>:0 
[mono]   at Java.Lang.Object.GetObject[IRunnable] (IntPtr handle, JniHandleOwnership transfer) [0x00000] in <filename unknown>:0 
[mono]   at Java.Lang.Object.GetObject[IRunnable] (IntPtr jnienv, IntPtr handle, JniHandleOwnership transfer) [0x00000] in <filename unknown>:0 
[mono]   at Java.Lang.IRunnableInvoker.n_Run (IntPtr jnienv, IntPtr native__this) [0x00000] in <filename unknown>:0 
[mono]   at (wrapper dynamic-method) object:f47b3182-2f06-419f-97f3-4b389b007bb9 (intptr,intptr)
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.NotSupportedException: Unable to activate instance of type Java.Lang.Thread+RunnableImplementor from native handle be9ea02c ---> System.MissingMethodException: No constructor found for Java.Lang.Thread+RunnableImplementor::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
[mono-rt] Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
[mono-rt] 
[mono-rt]   --- End of managed exception stack trace ---
[mono-rt] java.lang.Error: Java callstack:
[mono-rt] 	at mono.java.lang.RunnableImplementor.n_run(Native Method)
[mono-rt] 	at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
[mono-rt] 	at android.os.Handler.handleCallback(Handler.java:739)
[mono-rt] 	at android.os.Handler.dispatchMessage(Handler.java:95)
[mono-rt] 	at android.os.Looper.loop(Looper.java:145)
[mono-rt] 	at android.app.ActivityThread.main(ActivityThread.java:5944)
[mono-rt] 	at java.lang.reflect.Method.invoke(Native Method)
[mono-rt] 	at java.lang.reflect.Method.invoke(Method.java:372)
[mono-rt] 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389)
[mono-rt] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184)
[mono-rt] 
[mono-rt]   --- End of inner exception stack trace ---
[mono-rt]   at Java.Interop.TypeManager.CreateProxy (System.Type type, IntPtr handle, JniHandleOwnership transfer) [0x00000] in <filename unknown>:0 
[mono-rt]   at Java.Interop.TypeManager.CreateInstance (IntPtr handle, JniHandleOwnership transfer, System.Type targetType) [0x00000] in <filename unknown>:0 
[mono-rt]   --- End of inner exception stack trace ---
[mono-rt]   at Java.Interop.TypeManager.CreateInstance (IntPtr handle, JniHandleOwnership transfer, System.Type targetType) [0x00000] in <filename unknown>:0 
[mono-rt]   at Java.Lang.Object.GetObject (IntPtr handle, JniHandleOwnership transfer, System.Type type) [0x00000] in <filename unknown>:0 
[mono-rt]   at Java.Lang.Object._GetObject[IRunnable] (IntPtr handle, JniHandleOwnership transfer) [0x00000] in <filename unknown>:0 
[mono-rt]   at Java.Lang.Object.GetObject[IRunnable] (IntPtr handle, JniHandleOwnership transfer) [0x00000] in <filename unknown>:0 
[mono-rt]   at Java.Lang.Object.GetObject[IRunnable] (IntPtr jnienv, IntPtr handle, JniHandleOwnership transfer) [0x00000] in <filename unknown>:0 
[mono-rt]   at Java.Lang.IRunnableInvoker.n_Run (IntPtr jnienv, IntPtr native__this) [0x00000] in <filename unknown>:0 
[mono-rt]   at (wrapper dynamic-method) object:f47b3182-2f06-419f-97f3-4b389b007bb9 (intptr,intptr)


Xamarin Studio
Version 5.7.1 (build 17)
Installation UUID: 880a449a-2ad9-45d3-89e5-c224da8dca65
Runtime:
	Mono 3.12.0 ((detached/de2f33f)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000076

Xamarin.Android
Version: 4.20.0.28 (Enterprise Edition)
Android SDK: /Users/yurys/Android/sdk
	Supported Android versions:
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

Apple Developer Tools
Xcode 6.1 (6604)
Build 6A1052d

Xamarin.iOS
Version: 8.6.1.20 (Enterprise Edition)
Hash: 3b3ef43
Branch: 
Build date: 2015-01-24 09:42:21-0500

Xamarin.Mac
Not Installed

Build Information
Release ID: 507010017
Git revision: 0bc7d3550b6b088ac25b08dcf7bbe73bcc8658b3
Build date: 2015-02-03 19:43:29-05
Xamarin addins: f7b7d34419c9ec24501bfa7c658e80a6305613e0

Operating System
Mac OS X 10.10.0
Darwin Mac-mini-Admin.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 1 Jonathan Pryor 2015-02-25 11:35:58 UTC
This doesn't make sense. :-(

What's happening is that SynchronizationContext.Current.Post() is in fact calling Android.App.Application.SynchronizationContext.Post() (the joy of controlling everything!), and Application.SynchronizationContext.Post() does:

  using (var h = new Android.OS.Handler(Application.Context.MainLooper)) {
    h.Post (() => d (state));
  }

Handler.Post(Action), in turn, creates an instance of the internal Thread.RunnableImplementor type, which implements Java.Lang.IRunnable, allowing Handler.Post(Action) to in turn call Handler.Post(IRunnable):

http://developer.android.com/reference/android/os/Handler.html#post(java.lang.Runnable)

Thread.RunnableImplementor  implements IRunnable.Run() to do two things:

 1. Invoke the Action, and
 2. Dispose() of the RunnableImplementor type.

(2) is to keep the GREF count lower without involving the GC, on the assumption that Runnable.run() will only be invoked once. (This is something we need to manually check, otherwise we need to use another IRunnable implementation.)

What I'm guessing is happening on your devices is that Runnable.run() is being invoked *twice*: the first time runs as-normal, then Dispose()s of the instance, and then Runnable.run() is invoked a *second* time, which promptly breaks because there's no longer a Thread.RunnableImplementor instance registered for that particular Java instance.

...which makes no sense: as per the above Android docs, Handler.post(Runnable) should only invoke the Runnable once, not multiple times.
Comment 2 Jonathan Pryor 2015-02-25 11:39:38 UTC
How long does it take Attachment #10026 [details] to fail on your devices?

Could you please enable GREF logging and attach the `adb logcat` output of the *entire* app run?

    $ adb shell setprop debug.mono.log gref,gc
    $ adb logcat > log.txt &
    $ xbuild /t:_Run YourProject.csproj

When the app crashes, press `Ctrl+C` in the shell and attach the generated log.txt file.

The GREF log will allow me to determine if the handle is in fact being disposed from Run() and that the crash is due to a second run() invocation, or whether something crazier is going on...
Comment 3 YuraS 2015-02-26 02:27:30 UTC
Created attachment 10042 [details]
adb logcat output
Comment 4 YuraS 2015-02-26 02:27:52 UTC
Sample fails after a few seconds (5 - 30).
I attached logs of `xbuild /t:_Run /p:Configuration=Release` output.
Comment 5 Jonathan Pryor 2015-02-26 08:49:17 UTC
Thank you for Attachment #10042 [details].

Something strange is going on. :-(

Firstly, this is Xamarin.Android 4.20 running on `art`. It *should* be printing the message:

> JNI weak global refs are broken on Android with the ART runtime.
> Trying to use java.lang.WeakReference instead, but this may fail as well.
> App stability may be compromised.
> See: https://code.google.com/p/android/issues/detail?id=63929

However, that message isn't present in your `adb logcat` output.

Are you setting the debug.mono.wref system property?

That aside, my guess in Comment #1 is wrong. I thought (hoped?) that Run() was being invoked twice. That doesn't appear to be the case.

The only place that handle value be9ea02c appears is in the NotSupportedException message -- there is no +g+ message for that handle value!

There are two possibilities here:

1. We're hitting the previous, supposedly fixed, ART bug with JNI weak references:

http://forums.xamarin.com/discussion/comment/38456/#Comment_38456

2. The +g+ message is being skipped.

I don't think that (1) is likely here, as it appears when "similar" handle values appear/disappear, in which the lower ~24 bytes bytes "reappear" while the upper bytes differ. I don't see that here; for handle value be9ea02c, there are no other occurrences of a02c.

Which brings us to (2): I have observed [0] that `adb logcat` will DROP messages. (Years ago it was reportedly implemented as a ring buffer, so it was never fully reliable, but the message dropping I've observed is NOT that of a ring buffer; *recent* messages are skipped!)

Which means everything is suspect: we could be hitting (1), and the +g+ message wasn't written "Just Because". Or, we have seen handle value be9ea02c before -- or some alias -- and the +g+ message was similarly skipped.

The unreliability of GREF logging on Lollipop is disheartening.

"Fortunately", I've reworked the GREF logging mechanism in Xamarin.Android 5.1 to avoid `adb logcat`. Unfortunately, that's not yet public.

We'll need to see if we can repro locally . (I know it doesn't repro on my Nexus 5...)

[0]: https://bugzilla.xamarin.com/show_bug.cgi?id=25443#c23
Comment 6 Jonathan Pryor 2015-03-02 15:33:36 UTC
@PeterC: Please test Attachment #10026 [details] against master or 5.1 with GREF logging enabled on one of the devices from Comment #0:

> Samsung GT-I9500 Galaxy S IV (Android 5.0.1)
> Samsung SM-N900 Galaxy Note 3 (Android 5.0)
Comment 8 Anton 2015-03-13 06:18:30 UTC
This bug constantly reproduces on Samsung devices with Android Lollipop.
Do you have any updates for current issue?
We're looking forward to hearing from you.
Comment 9 Yann ROBIN 2015-03-16 06:00:40 UTC
We do have the same issue with our application, and we're getting bad rating because of it !

Could you please give us an update on this issue ?
Comment 10 Steve Gordon 2015-03-17 17:33:36 UTC
We are seeing this as well. It's currently our #1 crash.
Comment 11 Peter Collins 2015-03-23 15:47:30 UTC
We've received an OTA Lollipop update for a GS5, and I am able to reproduce this failure with the test case attached:
https://gist.github.com/pjcollins/e12279350c945b9354dc

However, I'm not seeing this crash with gref logging enabled. Here's the grefs.txt I've pulled from my device after a few minutes of execution:
https://www.dropbox.com/s/s2g42st4e07lejo/grefs.txt.zip?dl=0
Comment 12 Michal Krysinski 2015-03-24 09:59:59 UTC
Samsung S5 with Lollipop, same problem. Very important.
Comment 13 KP 2015-03-24 14:39:01 UTC
We have the same issue on Samsung S5 with Lollipop. We are hit by this error daily, so it is very critical for us as well!
Comment 14 David Reynolds 2015-04-01 04:20:17 UTC
We are seeing a lot of error reports because of this issue. Do you know when it will be resolved?
Comment 15 Jonathan Pryor 2015-04-01 09:02:12 UTC
> Do you know when it will be resolved?

Once I understand *why* it's actually happening, which has so far eluded me.
Comment 16 cg 2015-04-01 09:55:49 UTC
We have exactly the same problem on Samsung S5 with lollipop. This is very critical. We really hope you see this issue as a top priority to solve.
Comment 17 Nir Azulay 2015-04-01 10:30:26 UTC
Any Updates?
Comment 18 Miguel de Icaza [MSFT] 2015-04-02 16:48:20 UTC
Fixing status.
Comment 19 Jonathan Pryor 2015-04-04 11:40:39 UTC
Fixed in monodroid/ea65174b and monodroid-5.1-series/193e91fb.

This didn't make it into the current Xamarin.Android 5.1 alpha, but it should be in the forthcoming beta.
Comment 20 KP 2015-04-04 14:48:01 UTC
Great that it has been fixed. What's the ETA for this to be in a stable release?
Comment 21 Peter Collins 2015-04-08 12:19:17 UTC
Verified fixed in mono-android-4.20.2-1 and Xamarin.VisualStudio_3.9.546. These builds should be available in the Beta channel today, and Stable by the end of the week.
Comment 22 Mikhail Melnik 2015-05-06 16:26:20 UTC
I'm still getting similar crashes after update. Here is my configuration


Xamarin Studio
Version 5.9 (build 431)
Installation UUID: 2ce9ad5e-1900-473f-a546-f3944667d60e
Runtime:
	Microsoft .NET 4.0.30319.34209
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

Xamarin.Android
Version: 5.1.0 (Indie Edition)
Android SDK: D:\Development\Android\bundle\sdk
	Supported Android versions:
		4.0.3 (API level 15)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: C:\Program Files\Java\jdk1.7.0_51
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)



and crash 



[MonoDroid] UNHANDLED EXCEPTION:
[MonoDroid] System.NotSupportedException: Unable to activate instance of type Java.Lang.Thread+RunnableImplementor from native handle f690001d ---> System.MissingMethodException: No constructor found for Java.Lang.Thread+RunnableImplementor::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
[MonoDroid] Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
[MonoDroid]   --- End of managed exception stack trace ---
[MonoDroid] java.lang.Error: Java callstack:
[MonoDroid] 	at mono.java.lang.RunnableImplementor.n_run(Native Method)
[MonoDroid] 	at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:29)
[MonoDroid] 	at android.os.Handler.handleCallback(Handler.java:730)
[MonoDroid] 	at android.os.Handler.dispatchMessage(Handler.java:92)
[MonoDroid] 	at android.os.Looper.loop(Looper.java:176)
[MonoDroid] 	at android.app.ActivityThread.main(ActivityThread.java:5419)
[MonoDroid] 	at java.lang.reflect.Method.invokeNative(Native Method)
[MonoDroid] 	at java.lang.reflect.Method.invoke(Method.java:525)
[MonoDroid] 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
[MonoDroid] 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
[MonoDroid] 	at dalvik.system.NativeStart.main(Native Method)
[MonoDroid]   --- End of inner exception stack trace ---
[MonoDroid]   at Java.Interop.TypeManager.CreateProxy (System.Type type, IntPtr handle, JniHandleOwnership transfer) [0x00039] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:267 
[MonoDroid]   at Java.Interop.TypeManager.CreateInstance (IntPtr handle, JniHandleOwnership transfer, System.Type targetType) [0x001ea] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:249 
[MonoDroid]   --- End of inner exception stack trace ---
[MonoDroid] at Java.Interop.TypeManager.CreateInstance (intptr,Android.Runtime.JniHandleOwnership,System.Type) [0x0022b] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/src/Java.Interop/TypeManager.cs:255
[MonoDroid] at Java.Lang.Object.GetObject (intptr,Android.Runtime.JniHandleOwnership,System.Type) [0x000e5] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:373
[MonoDroid] at Java.Lang.Object._GetObject<Java.Lang.IRunnable> (intptr,Android.Runtime.JniHandleOwnership) <0x000cf>
[MonoDroid] at Java.Lang.Object.GetObject<Java.Lang.IRunnable> (intptr,Android.Runtime.JniHandleOwnership) <0x0006f>
[MonoDroid] at Java.Lang.Object.GetObject<Java.Lang.IRunnable> (intptr,intptr,Android.Runtime.JniHandleOwnership) <0x0008b>
[MonoDroid] at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00000] in /Users/builder/data/lanes/monodroid-mavericks-monodroid-5.1-series/d23da369/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Java.Lang.IRunnable.cs:70
[MonoDroid] at (wrapper dynamic-method) object.ec3ed5a5-f6fb-4e38-bc62-17edbd9dea95 (intptr,intptr) <IL 0x00011, 0x0004b>
Comment 23 Jonathan Pryor 2015-05-06 17:00:34 UTC
@Mikhail Melnik: Which Android device do you see this on?

Is this with Attachment #10026 [details] or another app?
Comment 24 Mikhail Melnik 2015-05-06 17:14:54 UTC
Device is LG G3 (LG-D855) with Android 5.0 (Kernel 3.4.0). I'm working on company's product and sometimes release version crashes 3-4 times on start and then works well. The worst thing it is not consistent.
Comment 25 Andy 2016-03-02 13:11:45 UTC
I'm seeing this in the Cycle 7 Alpha with a Samsung Tab S2
Comment 26 Andy 2016-03-02 13:12:33 UTC
Relevant exception:

System.NotSupportedExceptionUnable to activate instance of type Java.Lang.Thread+RunnableImplementor from native handle 0xbeae9fbc (key_handle 0x22eed039).
Raw
Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, Type type)
Java.Lang.Object._GetObject<T>(IntPtr handle, JniHandleOwnership transfer)
Java.Lang.Object.GetObject<T>(IntPtr handle, JniHandleOwnership transfer)
Java.Lang.Object.GetObject<T>(IntPtr jnienv, IntPtr handle, JniHandleOwnership transfer)
Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this)
at (wrapper dynamic-method) System.Object:62c6b153-eeef-41f9-909f-2ecaf6791dfa (intptr,intptr)
System.MissingMethodExceptionNo constructor found for Java.Lang.Thread+RunnableImplementor::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)
Java.Interop.TypeManager.CreateProxy(Type type, IntPtr handle, JniHandleOwnership transfer)
Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, Type targetType)
Comment 27 Peter Collins 2016-03-02 17:28:34 UTC
@Andy I'm unable to reproduce this against the current Alpha using a Galaxy Tab S, the Galaxy S5 I was able to originally reproduce with, and a LG G4. I attempted this reproduction using the project attached in this bug. 

Are you seeing this crash with https://bugzilla.xamarin.com/attachment.cgi?id=10026? If not, would you be able to provide a small solution which reproduces this crash for you?

I'll also refer to comment #2: Could you please enable GREF logging and attach the `adb logcat` output of the *entire* app run?

    $ adb shell setprop debug.mono.log gref,gc
    $ adb logcat -c
    $ adb logcat > log.txt &
    $ Launch your app (xbuild/msbuild /t:_Run YourProject.csproj)

When the app crashes, press `Ctrl+C` in the shell that's redirecting logcat and attach the generated log.txt file.
Comment 28 Jonathan Pryor 2016-03-03 14:20:35 UTC
In addition to the commands in Comment #27, please also run:

> $ adb shell run-as @PACKAGE_NAME@ cat files/.__override__/grefs.txt > grefs.txt

where @PACKAGE_NAME@ is the package name of your application, which is also the basename of the .apk that is installed.

grefs.txt contains stack traces when creating and destroying JNI global references, which `adb logcat` doesn't contain.
Comment 29 adrianknight89 2016-03-06 03:17:49 UTC
I'm having this System.NotSupportedException exception everywhere. It's annoying. I have a ListView with a rowheight of 60 units and over 200 items. If I scroll down/up fast enough, the app will crash with this exception.

I created a similar bug: https://bugzilla.xamarin.com/show_bug.cgi?id=39189

In the above case, I was invoking tapped events frequently by tapping on the screen, so eventually the app would crash. This is a serious bug IMO and it needs to be fixed ASAP. No production app can be taken seriously with such an issue.
Comment 30 adrianknight89 2016-03-06 03:19:34 UTC
I should add the following are my configs

Xamarin Forms 2.1.0.6521
Compile using Android 6.0 Marshmallow
Minimum target Android 4.4 (SDK 19)
Comment 31 adrianknight89 2016-03-06 03:51:04 UTC
Created attachment 15278 [details]
adb log

Here's my own adb output. For grefs.txt, I had nothing but 

"run-as: Package 'com.yourcompany.App26New' is unknown"

I'm also using Cycle 7.