Bug 28919 - Debug failure with lollipop
Summary: Debug failure with lollipop
Status: RESOLVED DUPLICATE of bug 29365
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 5.2
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2015-04-09 04:28 UTC by Sam Pollock
Modified: 2015-04-28 11:38 UTC (History)
8 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 Sam Pollock 2015-04-09 04:28:50 UTC
Many of us have been experiencing major issues debugging code when running an app on a device running lollipop, please take a look at the following thread. 


Xamarin will throw null reference exceptions all over the place for no reason, the code will work fine under release and also on a device running kitkat
Comment 1 Ben Beckley 2015-04-09 19:00:11 UTC
Hello Sam,

Could you please provide some additional information about your Xamarin Studio details and OS version please? I'd like to set up my environment to match yours so I can reproduce this.

I tried to reproduce with OS X 10.10.2, Xamarin Studio 5.8.3, and Xamarin Android with a Nexus 7 on 5.02 but it was to no avail. Also, if you could provide a simple code sample that reproduces the issue and include some steps, it would make things go much faster. Thank you.
Comment 2 Mikhail Melnik 2015-04-09 21:00:43 UTC
Hi Ben,

I had the same issue a few days ago and here is my configuration

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

Version: 4.20.0 (Indie Edition)
Android SDK: D:\Development\Android\bundle\sdk
	Supported Android versions:
		2.2   (API level 8)
		4.0   (API level 14)
		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)

Xamarin Android Player
Not Installed

Build Information
Release ID: 508020007
Git revision: 067ed06873402cf780f8a0899bb332c2a1c0af22
Build date: 2015-03-27 10:01:55-04
Xamarin addins: 02510c4990dee3475c282b3182d588975a63ff07

Operating System
Windows 6.2.9200.0 (64-bit)

I'm using LG G3 with Lollipop to debug.

First thing I've noticed is NPEs on breakpoint line. Not sure was it only case or not but I remember it happened within application assembly only. 

Another thing was I wasn't able to set a new breakpoint during debug session. So I have to stop debugging, set new breakpoint and run again.

Comment 3 Jonathan Pryor 2015-04-09 21:27:26 UTC
> Version: 4.20.0 (Indie Edition)

Please try 4.20.1 or later, as it contains a fix for the JIT when running on Android 5.0:


Better, use 4.20.2, which contains additional fixes for running on Android 5.0.
Comment 4 agimenez 2015-04-10 04:16:41 UTC

I have the 4.20.2 version and still have the same problem.

Xamarin Studio
Version 5.8.3 (build 1)
Installation UUID: f27d5f7f-e26e-4128-8b69-f61779b082a5
	Microsoft .NET 4.0.30319.34209
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.25

Version: 4.20.2 (Indie Edition)
Android SDK: d:\android-sdk
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		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: C:\Program Files (x86)\Java\jdk1.7.0_67
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) Client VM (build 24.65-b04, mixed mode, sharing)

Xamarin Android Player
Not Installed

Build Information
Release ID: 508030001
Git revision: 6e8e725e0d689351901c2c70453bfa4ea25e293b
Build date: 2015-04-06 15:20:49-04
Xamarin addins: 051cd5f8c1b5dbfc87eaef80a74aec03f34c60a8

Operating System
Windows 6.1.7601.65536 (64-bit)
Comment 5 Sam Pollock 2015-04-13 05:09:13 UTC
Hi Ben, sorry I did not get back to you earlier, been away. I downloaded the latest xamarin updates today and am still having the same issues.

Xamarin Studio
Version 5.8.3 (build 1)
Installation UUID: 720e1bd4-2969-4af2-a2ed-7f7d50e8e9c9
	Mono 3.12.1 ((detached/0849ec7)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312010003

Apple Developer Tools
Xcode 6.2 (6776)
Build 6C131e

Not Installed

Version: (Business Edition)
Android SDK: /Users/welshrat77/Documents/Apps/android-sdk-macosx
	Supported Android versions:
		1.6    (API level 4)
		2.1    (API level 7)
		2.2    (API level 8)
		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"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

Xamarin Android Player
Not Installed

Version: (Business Edition)
Hash: f7736a4
Build date: 2015-04-09 04:22:08-0400

Build Information
Release ID: 508030001
Git revision: 6e8e725e0d689351901c2c70453bfa4ea25e293b
Build date: 2015-04-06 20:31:47-04
Xamarin addins: 051cd5f8c1b5dbfc87eaef80a74aec03f34c60a8

Operating System
Mac OS X 10.10.2
Darwin Sams-MBP.lan 14.1.0 Darwin Kernel Version 14.1.0
    Mon Dec 22 23:10:38 PST 2014
    root:xnu-2782.10.72~2/RELEASE_X86_64 x86_64
Comment 6 Sam Pollock 2015-04-13 05:15:19 UTC
An example of the issue is creating a background service and then on my activity 

App.Current.LocationServiceConnected += BindLocationServices;

It will give a null reference exception on the above when debugging under lollipop but is fine under release and under kitkat.

if needed I can send a load more code across.
Comment 7 Sam Pollock 2015-04-13 05:22:40 UTC
I am also seeing this in the console if it helps

JNI RegisterNativeMethods: attempt to register 0 native methods for goyonder.LocationServiceBinder

Not seen this before.
Comment 8 Jonathan Pryor 2015-04-13 10:54:38 UTC
> I am also seeing this in the console if it helps
> JNI RegisterNativeMethods: attempt to register 0 native methods for goyonder.LocationServiceBinder

That's just ART. It's ignorable.
Comment 9 Jonathan Pryor 2015-04-13 10:56:54 UTC
>     App.Current.LocationServiceConnected += BindLocationServices;
> It will give a null reference exception on the above when debugging.

What's the stack trace for the NullReferenceException?
Comment 10 agimenez 2015-04-15 09:40:59 UTC
This is one type of exception:

$exception	{System.NullReferenceException: Object reference not set to an instance of an object
at Android.Runtime.JNIEnv.WaitForBridgeProcessing () [0x00000] in /Users/builder/data/lanes/1353/86274adf/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:244
at (wrapper dynamic-method) object.ecd91cdd-fc66-4f74-b5e2-5b90f03cd128 (intptr,intptr) <IL 0x00000, 0x00023>
at (wrapper native-to-managed) object.ecd91cdd-fc66-4f74-b5e2-5b90f03cd128 (intptr,intptr) <IL 0x0001a, 0x0006b>
}	System.NullReferenceException

This is another:

$exception	{System.NullReferenceException: Object reference not set to an instance of an object
at System.Threading.Timer..ctor (System.Threading.TimerCallback,object,int,int) <IL 0x00000, 0x00040>
at (wrapper remoting-invoke-with-check) System.Threading.Timer..ctor (System.Threading.TimerCallback,object,int,int) <IL 0x0001e, 0x000b7>
at System.Timers.Timer..ctor (double) <IL 0x00072, 0x002b3>
at System.Timers.Timer..ctor () <IL 0x0000a, 0x0005b>
at (wrapper remoting-invoke-with-check) System.Timers.Timer..ctor () <IL 0x00019, 0x00047>
at homecontrol.CustomCordovaActivity/cltAPI16.OnPageFinished (Android.Webkit.WebView,string) [0x00060] in c:\pgap\xamarin\PgapAndroid\PgapAndroid\Activities\CustomCordovaActivity.cs:2380
at Android.Webkit.WebViewClient.n_OnPageFinished_Landroid_webkit_WebView_Ljava_lang_String_ (intptr,intptr,intptr,intptr) [0x00019] in /Users/builder/data/lanes/1353/86274adf/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Webkit.WebViewClient.cs:167
at (wrapper dynamic-method) object.208407c6-1167-4b55-a9f6-d3eb82146f0d (intptr,intptr,intptr,intptr) <IL 0x0001d, 0x0004b>
}	System.NullReferenceException

Comment 11 agimenez 2015-04-15 12:29:58 UTC
As a note, for the second exception happens just instancing a Timer, if I add a 

System.Diagnostics.Debugger.Break ();

just before instancing the timer it works most times.
Comment 12 Sam Pollock 2015-04-16 06:26:59 UTC
I am a bit confused, I have just come back today after a few days out and am happily debugging on the nexus 5, I have not done anything to my code and I have not made any software updates however the problem now appears to be fixed, I will feedback if this reoccurs. The only change was some apple updates to yosimite.
Comment 13 Sam Pollock 2015-04-16 06:27:25 UTC
Sorry I meant nexus 7
Comment 14 Sam Pollock 2015-04-16 07:11:43 UTC
A quick update, I have had the issue occur once this morning, There was no stack trace and a null reference was thrown, I rebuilt and it seems to have gone again.
Comment 15 Sam Pollock 2015-04-16 09:00:27 UTC
Ok Got another one on a simple thread start.

Here is the stack trace

at intptr.op_Explicit (int) <IL 0x00000, 0x00028>
at System.Threading.Thread.Start () <IL 0x0003a, 0x001cf>
at GoYonder.UI.LoginActivity/<OnCreate>c__AnonStorey0.<>m__0 (object,System.EventArgs) [0x0005b] in /Users/welshrat77/Documents/Work/xamarin/GoYonda/YondageoAndroid/Testbed/Testbed/UI/LoginActivity.cs:194
at Android.Views.View/IOnClickListenerImplementor.OnClick (Android.Views.View) [0x0000d] in /Users/builder/data/lanes/1353/86274adf/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View.cs:2020
at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/1353/86274adf/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View.cs:1987
at (wrapper dynamic-method) object.361e638f-a544-43ae-a190-1462ca5ea472 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
Comment 16 Sam Pollock 2015-04-16 09:01:24 UTC
I also see this in the console whenever a crash occurs

[chromium] ### WebView Version 40 (1832189-arm) (code 424501)
Comment 17 Sam Pollock 2015-04-16 09:07:37 UTC
And Another at a completely different thread and part of the app at the line

ThreadPool.QueueUserWorkItem (o => {

The stack trace is :-

  at GoYonder.LocationServiceBound+<FindNearbyWaypointDirection>c__AnonStorey1.<>m__0 (System.Object o) [0x00000] in /Users/welshrat77/Documents/Work/xamarin/GoYonda/YondageoAndroid/Testbed/Testbed/Core/Services/LocationServiceBound.cs:230 

which is the above line.

again am seeing this.

[chromium] ### WebView Version 40 (1832189-arm) (code 424501)

which is probably unrelated but am posting anyway.
Comment 18 Sam Pollock 2015-04-16 09:13:07 UTC
Sorry for the bombardment but am just trying to give as much info as possible, I had been running the nexus 7 under debug all morning without issue however now its crashing all over the place so I have had to resort to my lg pad running kitkat and all is fine again.
Comment 19 Jonathan Pryor 2015-04-16 09:35:57 UTC
@Sam: When you see the [chromium] message, is that from your process ID?


Are you using Chromium? What device is this? Is it possible you're hitting Bug #27455, in which Chromium SEGFAULTS and everything becomes "weird":


Could you please provide the complete `adb logcat` output of your app run?
Comment 20 Sam Pollock 2015-04-16 10:00:07 UTC
Hi Jonathan, I am just using a standard webview however I guess this defaults to the browser installed on the device, The device is a nexus 7 running lollipop 5.02.

It is possible that I am hitting that bug as a page prior to the one with the most issues has a webview within a fragment (something which I can actually remove)

I will attempt to get the full logcat but it might not be today.

Cheers Sam
Comment 22 Sam Pollock 2015-04-21 10:35:00 UTC
Hi all, I have made some changes to my app so that the webview is no longer in a fragment and as soon as I add breakpoints etc or at random times when debugging I am still getting null reference exceptions under lollipop.

This is still appearing in my console.
[chromium] ### WebView Version 40 (1832189-arm) (code 424501)

And I will get the problem on the most basic of syntax such as variable declaration. Again the issue is not visible under kitkat or under release.

Cheers Sam
Comment 23 Sam Pollock 2015-04-21 11:20:33 UTC
On Reading around it appears many people are seeing this bug and not just under xamarin, 

[chromium] ### WebView Version 40 (1832189-arm) (code 424501)

Does anyone have any idea whether Google is aware of this and if any fix is incoming, it must be the way the debugger connects as the issue is not visible under release.
Comment 24 Ben Beckley 2015-04-21 13:45:01 UTC
In my attempts to reproduce this issue, I found that Bug 28985 gives similar behavior to what you describe. I found that the trigger for the breakpoint NREs I'm seeing was updating Android System WebView to version 40. This was the case for both a Nexus 7 running 5.0.2 and a Nexus 9 running 5.0.1.

Have you experienced the debugging errors with an app that does not use a WebView? If so, then could you please give a code/project sample that reproduces the issue?
Comment 25 Sam Pollock 2015-04-22 04:47:24 UTC
Hi Ben, this appears to be the exact issue, all my current apps use a webview hence why I am seeing this issue. however looking at that bug it appears to have wider consequences than breakpoints as my location service will not start correctly and I will get other strange issues, but again only under lollipop and only when using a webview.

I am guessing this is not a xamarin issue but a problem with the new webview, If this is the case how are we best to obtain a resolution.
Comment 26 Sam Pollock 2015-04-22 04:48:05 UTC
Just to add only in debug
Comment 27 Ben Beckley 2015-04-22 13:11:23 UTC
Hello Sam, thank you for letting us know that. To my knowledge, Android System WebView is specifically for lollipop and comes installed on Android devices. It is maintained by Google Inc. and thus I am not sure what Xamarin can do about it. @Jonathan Pryor may be able to shine more light onto this situation.

I have been searching for a workaround, but haven't found a solution yet. The current Android System WebView version is 40. This is the lowest version that I know which reproduces the debugging issue. Also, I opted into the beta channel for Android System WebView and found that the latest beta version is 42.0.2311.139. When debugging with a breakpoint, I no longer get an NRE. Instead the app will crash to home screen and the debugger stops.

For now I will wait on a new beta version that includes a fix. Another option I will explore is obtaining an older version that does not have the issue.
Comment 28 Olaf Bartelt 2015-04-24 04:12:27 UTC
I'm having the same issue. App with a WebView, Motorola Moto G (1st edition), Android 5.0.2. Crashes in debug mode at random places, works fine when not connected to the debugger (same build in debug mode). Stack traces differ, but I often get this as exception details:

0x0 in Android.Runtime.JNIEnv.WaitForBridgeProcessing at /Users/builder/data/lanes/1353/86274adf/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:244,4
Comment 29 Ben Beckley 2015-04-27 11:24:56 UTC
Hello, there is potentially a workaround that will allow the use of breakpoints without a crash. It is in the sixth comment of Bug 29365. The process of how to implement it is in the second comment of the aforementioned bug along with additional information about the issue.
Comment 30 agimenez 2015-04-28 06:46:50 UTC
Ok, tested workaround and works like a charm:

-Add a new file to your project (in my case I added AndroidEnv) and set it's construction action to "AndroidEnvironment"
-Add "MONO_DEBUG=explicit-null-checks,soft-breakpoints" to it
-Enjoy debugging again!
Comment 31 Ben Beckley 2015-04-28 11:38:35 UTC
This issue is better tracked and described in the bug which has the workaround.

*** This bug has been marked as a duplicate of bug 29365 ***