Bug 27455 - JNI crash caused by WebView
Summary: JNI crash caused by WebView
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries (show other bugs)
Version: 4.20.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Marek Habersack
URL:
: 27454 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-02-26 08:02 UTC by Roman Cervenak
Modified: 2016-04-11 14:53 UTC (History)
7 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Roman Cervenak 2015-02-26 08:02:21 UTC
When I add fragment containing WebView in runtime, sometimes I get following error:

[0:] 
AppDomain.CurrentDomain.UnhandledException: System.NullReferenceException: Object reference not set to an instance of an object
02-26 13:32:05.712 I/mono-stdout(25277): AppDomain.CurrentDomain.UnhandledException: System.NullReferenceException: Object reference not set to an instance of an object
[0:] AppDomain.CurrentDomain.UnhandledException: System.NullReferenceException: Object reference not set to an instance of an object
at Android.Runtime.JNIEnv.WaitForBridgeProcessing () [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:244
at (wrapper dynamic-method) object.4d5f30d3-5394-460b-9ef4-656789c76f49 (intptr,intptr) <IL 0x00000, 0x00023>
at (wrapper native-to-managed) object.4d5f30d3-5394-460b-9ef4-656789c76f49 (intptr,intptr) <IL 0x0001a, 0x0006b>
. IsTerminating: True
at Android.Runtime.JNIEnv.WaitForBridgeProcessing () [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:244
at (wrapper dynamic-method) object.4d5f30d3-5394-460b-9ef4-656789c76f49 (intptr,intptr) <IL 0x00000, 0x00023>
at (wrapper native-to-managed) object.4d5f30d3-5394-460b-9ef4-656789c76f49 (intptr,intptr) <IL 0x0001a, 0x0006b>
. IsTerminating: True
02-26 13:32:05.712 I/mono-stdout(25277): at Android.Runtime.JNIEnv.WaitForBridgeProcessing () [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:244
02-26 13:32:05.713 I/mono-stdout(25277): at (wrapper dynamic-method) object.4d5f30d3-5394-460b-9ef4-656789c76f49 (intptr,intptr) <IL 0x00000, 0x00023>
02-26 13:32:05.714 I/mono-stdout(25277): at (wrapper native-to-managed) object.4d5f30d3-5394-460b-9ef4-656789c76f49 (intptr,intptr) <IL 0x0001a, 0x0006b>
02-26 13:32:05.714 I/mono-stdout(25277): . IsTerminating: True
02-26 13:32:05.719 E/mono-rt (25277): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
02-26 13:32:05.719 E/mono-rt (25277): at Android.Runtime.JNIEnv.WaitForBridgeProcessing () [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:244
02-26 13:32:05.719 E/mono-rt (25277): at (wrapper dynamic-method) object.4d5f30d3-5394-460b-9ef4-656789c76f49 (intptr,intptr) <IL 0x00000, 0x00023>
02-26 13:32:05.719 E/mono-rt (25277): at (wrapper native-to-managed) object.4d5f30d3-5394-460b-9ef4-656789c76f49 (intptr,intptr) <IL 0x0001a, 0x0006b>
02-26 13:32:05.719 E/mono-rt (25277): 

(Yes, I copied all of it, it just ends this way in log)
Nothing in the error seems to point to WebView, but it just happens only when I create and add this fragment (and it happens AFTER the fragment is shown and even webpage is loaded and displayed correctly in webview). My fragment is very simple:

public class HtmlPromoFragment : Fragment
    {
        private string promoUrl;

        public HtmlPromoFragment(string promoUrl)
        {
            this.promoUrl = promoUrl;
        }

        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.HtmlPromo, null);
            return view;
        }

        public override void OnResume()
        {
            base.OnResume();

            using (var webView = View.FindViewById<WebView>(Resource.Id.webviewPromo))
            {
                webView.SetWebViewClient(new HtmlPromoWebViewClient(this.Activity));
                webView.LoadUrl(promoUrl);
            }
        }
    }

and my HtmlPromoWebViewClient only overrides ShouldOverrideUrlLoading.
Comment 1 Jonathan Pryor 2015-02-26 09:30:20 UTC
Please run `adb logcat` [0] and attach the full output from your app run.

What device are you observing this on?

[0]: http://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/android_debug_log/
Comment 2 Roman Cervenak 2015-02-26 09:33:53 UTC
Xiaomi MI3
Comment 4 Jonathan Pryor 2015-02-26 11:43:21 UTC
Thank you for the logcat output.

What's "funny" is this:

> 02-26 16:37:05.368 W/crash_handler(19894): Caught a crash, signum=11^M

Signal 11 is SIGSEGV, so "something" crashed...somewhere, and invoke a signal handler *other* than Mono's signal handler (which would write a "nice" SIGSEGV message, possibly the managed stack trace, and abort the process -- note that the process isn't aborted here).

I'm not sure what "crash_handler" is, but it IS coming from your process (pid 19894).

This might be enough information to go on:

https://www.google.com/search?q=W/crash_handler+Caught+a+crash,+signum=11

which brings us to a stackoverflow post about a crash in AdMob:

http://stackoverflow.com/questions/18804236/crash-with-admob-and-startactivity

which in turn suggests that it's a threading issue:

http://stackoverflow.com/a/18825196/83444

The above links mention AdMob, which you're not using (at least I don't see anything mentioning AdMob in logcat), but the underlying issue may remain:

Are you using threads, either implicitly or explicitly? Is "something" being done from the "wrong" thread?

> and my HtmlPromoWebViewClient only overrides ShouldOverrideUrlLoading.

What's HtmlPromoWebViewClient.ShouldOverrideUrlLoading() do?

This is a WebView, and I have to imagine that for performance reasons the WebView may internally use multiple threads, so it wouldn't surprise me that HtmlPromoWebViewClient.ShouldOverrideUrlLoading() were invoked from another thread (additional logging of System.Threading.Thread.CurrentThread.ManagedThreadId may be helpful ;-), so that's something to consider investigating.

If we further constrain the web search to ignore "admob" and include WebView:

https://www.google.com/search?q=W%2Fcrash_handler+Caught+a+crash%2C+signum%3D11+-admob+WebView

I find these two URLs with similar crashes...and lots of Chinese:

http://segmentfault.com/q/1010000002565062/a-1020000002565922
http://www.miui.com/thread-2224019-1-1.html

Unfortunately I can't read Chinese, but if I cheat:

https://translate.google.com/translate?hl=en&sl=zh-CN&tl=en&u=http%3A%2F%2Fwww.miui.com%2Fthread-2224019-1-1.html

...it appears that many others are seeing a similar crash, and one commenter suggests disabling hardware acceleration (e.g. [Activity(HardwareAccelerated=false)]).
Comment 5 Jonathan Pryor 2015-02-26 11:46:50 UTC
*** Bug 27454 has been marked as a duplicate of this bug. ***
Comment 6 Roman Cervenak 2015-02-26 12:07:13 UTC
1. I dont have AdMob in the project
2. HtmlPromoWebViewClient.ShouldOverrideUrlLoading contains just switch on url parameter, opening some other fragments, but whole this method body is inside Activity.RunOnUiThread(), so I dont see any obvious threading issue here.
3. i also have no idea what "crash_handler" is :/
Comment 7 Jonathan Pryor 2015-02-27 09:15:16 UTC
> 1. I dont have AdMob in the project

As I guessed in Comment #4.

> 2. HtmlPromoWebViewClient.ShouldOverrideUrlLoading contains just switch on url
> parameter, opening some other fragments, but whole this method body is inside
> Activity.RunOnUiThread(),

*Which* method body?

>  so I dont see any obvious threading issue here.

That's the fun thing about threads: they can appear out of nowhere. :-(

You should also try disabling hardware acceleration, as suggested in Comment #4.

> 3. i also have no idea what "crash_handler" is :/

Best as I can tell, it's something within Chromium, but I'm not entirely sure.
Comment 8 Roman Cervenak 2015-03-06 08:39:06 UTC
Today I discovered something that seems to resolve the issue - clear and disable cache (dont ask me why clear is needed even if cache use is disabled, but for me, it works only then) :

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {            
            webView = new WebView(this.Activity);
            webView.ClearCache(true);
            webView.Settings.CacheMode = CacheModes.NoCache; 
            webView.LayoutParameters = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);

            return webView;
        }

and the error is gone...
Comment 9 Roman Cervenak 2015-03-06 08:42:42 UTC
To be more exact, I still see the following in log, but it no longer crash the app: 

03-06 14:41:30.397 W/crash_handler( 8240): Caught a crash, signum=11
03-06 14:41:30.401 W/crash_handler( 8240): Caught a crash, signum=11
03-06 14:41:30.402 E/webcore ( 8240): Report WebCore crash to the ErrorReportUtils at:Fri Mar 06 14:41:30 CET 2015
03-06 14:41:30.405 E/webcore ( 8240): Report WebCore crash to the ErrorReportUtils at:Fri Mar 06 14:41:30 CET 2015
Comment 11 Sam Pollock 2015-04-20 04:47:29 UTC
Sorry I just posted an attachment to the wrong bug, appologies
Comment 12 JW 2015-12-30 18:21:10 UTC
I'm noticing random crashes like this as well when using a renderer for the WebView for Xamarin Forms.
Comment 13 Jason Couture 2016-01-07 13:50:14 UTC
I'm having the same issue:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="NightOwl.Views.Authentication.OAuthDialog">
  <WebView x:Name="Browser" Source=""></WebView>
</ContentPage>



        public OAuthDialog(ExternalLoginModel model)
        {
            _model = model;
            InitializeComponent();
            Browser.Navigating += BrowserOnNavigating;
            Browser.Navigated += BrowserOnNavigated;
            Browser.Source = new UrlWebViewSource() { Url = model.Url };
            
        }




Small snippet of logs:

01-07 08:37:02.170 E/eglCodecCommon( 1549): **** ERROR unknown type 0x9b62b238 (glSizeof,72)
01-07 08:37:02.171 E/eglCodecCommon( 1549): glUtilsParamSize: unknow param 0x00000b44
01-07 08:37:02.171 W/BindingManager( 1549): Cannot call determinedVisibility() - never saw a connection for the pid: 1549
Navigated: https://accounts.google.com/ServiceLogin?passive=1209600&continue=https://accounts.google.com/o/oauth2/auth?scope%3Dopenid%2Bprofile%2Bemail%26response_type%3Dcode%26redirect_uri%3Dhttps://nightowl.pssproducts.com/signin-google%26state%3DAxAAQAEIAA825-zxtJQeOPbQnviOpMpYkiEtfREUTffyZV6zdkFlsksdwG2WpVW3xQZmkF6lxgFyBCFcu1L0qFfBlxtCnK1ajhJ6PtIURUEkOU6_qVEvrLJjSBAtuMW9f_vQFaJ5Veux7ar0ukdpz-t3EZH0dOCBnzpIjdclwE4z9AfZLzP55qnlWr63qe_q52zTRXqsWMSlzFr5nLId70vabhGPbgCZU5P9eWr2y98bYvbm3gCZ9OXSvRzThBByxAE9Q1cFAb1Tr7QKshbizZXPxHahOcmijMl2N8unIUCWfUpVksPdRPjNQDLQdQNglRgcdsAjt6tCLF15WTjL2GKt3o5N-7nhGlq3NtWEtgXsf5kdlfPuqPzPhq3qGC3i-NbdN0Fvg4E2qdNUpx8NnvMy0ReOrOmoRDiAVqB9cLD3mzJp_1jJPH-T__5P2teCIlGwUX8ZDWCa0ktgKQwt%26client_id%3D281479877297-uqcqbmgoq3u5rrcpu8e2gp6jt4rp8e1o.apps.googleusercontent.com%26hl%3Den-US%26from_login%3D1%26as%3D-95e1248459b7f00&ltmpl=popup&oauth=1&sarp=1&scc=1#password - Success
01-07 08:37:02.171 I/mono-stdout( 1549): Navigated: https://accounts.google.com/ServiceLogin?passive=1209600&continue=https://accounts.google.com/o/oauth2/auth?scope%3Dopenid%2Bprofile%2Bemail%26response_type%3Dcode%26redirect_uri%3Dhttps://nightowl.pssproducts.com/signin-google%26state%3DAxAAQAEIAA825-zxtJQeOPbQnviOpMpYkiEtfREUTffyZV6zdkFlsksdwG2WpVW3xQZmkF6lxgFyBCFcu1L0qFfBlxtCnK1ajhJ6PtIURUEkOU6_qVEvrLJjSBAtuMW9f_vQFaJ5Veux7ar0ukdpz-t3EZH0dOCBnzpIjdclwE4z9AfZLzP55qnlWr63qe_q52zTRXqsWMSlzFr5nLId70vabhGPbgCZU5P9eWr2y98bYvbm3gCZ9OXSvRzThBByxAE9Q1cFAb1Tr7QKshbizZXPxHahOcmijMl2N8unIUCWfUpVksPdRPjNQDLQdQNglRgcdsAjt6tCLF15WTjL2GKt3o5N-7nhGlq3NtWEtgXsf5kdlfPuqPzPhq3qGC3i-NbdN0Fvg4E2qdNUpx8NnvMy0ReOrOmoRDiAVqB9cLD3mzJp_1jJPH-T__5P2teCIlGwUX8ZDWCa0ktgKQwt%26client_id%3D281479877297-uqcqbmgoq3u5rrcpu8e2gp6jt4rp8e1o.apps.googleusercontent.com%26hl%3Den-US%26from_login%3D1%26as%3D-95e1248459b7f00&ltmpl=popup&oauth=1&sarp=1&scc=1#password - Success
[0:] Navigated: https://accounts.google.com/ServiceLogin?passive=1209600&continue=https://accounts.google.com/o/oauth2/auth?scope%3Dopenid%2Bprofile%2Bemail%26response_type%3Dcode%26redirect_uri%3Dhttps://nightowl.pssproducts.com/signin-google%26state%3DAxAAQAEIAA825-zxtJQeOPbQnviOpMpYkiEtfREUTffyZV6zdkFlsksdwG2WpVW3xQZmkF6lxgFyBCFcu1L0qFfBlxtCnK1ajhJ6PtIURUEkOU6_qVEvrLJjSBAtuMW9f_vQFaJ5Veux7ar0ukdpz-t3EZH0dOCBnzpIjdclwE4z9AfZLzP55qnlWr63qe_q52zTRXqsWMSlzFr5nLId70vabhGPbgCZU5P9eWr2y98bYvbm3gCZ9OXSvRzThBByxAE9Q1cFAb1Tr7QKshbizZXPxHahOcmijMl2N8unIUCWfUpVksPdRPjNQDLQdQNglRgcdsAjt6tCLF15WTjL2GKt3o5N-7nhGlq3NtWEtgXsf5kdlfPuqPzPhq3qGC3i-NbdN0Fvg4E2qdNUpx8NnvMy0ReOrOmoRDiAVqB9cLD3mzJp_1jJPH-T__5P2teCIlGwUX8ZDWCa0ktgKQwt%26client_id%3D281479877297-uqcqbmgoq3u5rrcpu8e2gp6jt4rp8e1o.apps.googleusercontent.com%26hl%3Den-US%26from_login%3D1%26as%3D-95e1248459b7f00&ltmpl=popup&oauth=1&sarp=1&scc=1#password - Success
01-07 08:37:02.182 E/eglCodecCommon( 1549): glUtilsParamSize: unknow param 0x00000bd0
01-07 08:37:02.187 E/eglCodecCommon( 1549): **** ERROR unknown type 0x9b62b238 (glSizeof,72)
01-07 08:37:02.189 E/eglCodecCommon( 1549): glUtilsParamSize: unknow param 0x00000b44
01-07 08:37:02.196 E/eglCodecCommon( 1549): glUtilsParamSize: unknow param 0x00000bd0
01-07 08:37:02.203 E/eglCodecCommon( 1549): **** ERROR unknown type 0x9b62b238 (glSizeof,72)
01-07 08:37:02.205 E/eglCodecCommon( 1549): glUtilsParamSize: unknow param 0x00000b44
01-07 08:37:02.207 E/eglCodecCommon( 1549): glUtilsParamSize: unknow param 0x00000bd0
01-07 08:37:02.211 E/eglCodecCommon( 1549): **** ERROR unknown type 0x9b62b238 (glSizeof,72)
01-07 08:37:02.213 E/chromium( 1549): ### WebView Version 40 (1808730-x86) (code 400007)
Thread started:  #19
An unhandled exception occured.

WS: LostConnection
01-07 08:37:31.324 I/mono-stdout( 1549): WS: LostConnection
[0:] WS: LostConnection
WS: OnMessage({})
01-07 08:37:31.326 I/mono-stdout( 1549): WS: OnMessage({})
[0:] WS: OnMessage({})
01-07 08:37:31.328 E/mono    ( 1549): referenceTable GDEF length=814 1
referenceTable GSUB length=11364 1
referenceTable GPOS length=47302 1
referenceTable head length=54 1

01-07 08:37:31.328 E/mono    ( 1549): Unhandled Exception:
01-07 08:37:31.328 E/mono    ( 1549): System.NullReferenceException: Object reference not set to an instance of an object
01-07 08:37:31.328 E/mono    ( 1549):   at Android.Runtime.JNIEnv.WaitForBridgeProcessing () [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:256 
01-07 08:37:31.328 E/mono    ( 1549):   at (wrapper dynamic-method) System.Object:798c38f4-8167-4f16-ba11-423a8d31ba4d (intptr,intptr,int,int)
01-07 08:37:31.328 E/mono    ( 1549):   at (wrapper native-to-managed) System.Object:798c38f4-8167-4f16-ba11-423a8d31ba4d (intptr,intptr,int,int)
01-07 08:37:31.328 E/mono-rt ( 1549): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
01-07 08:37:31.328 E/mono-rt ( 1549):   at Android.Runtime.JNIEnv.WaitForBridgeProcessing () [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:256 
01-07 08:37:31.328 E/mono-rt ( 1549):   at (wrapper dynamic-method) System.Object:798c38f4-8167-4f16-ba11-423a8d31ba4d (intptr,intptr,int,int)
01-07 08:37:31.328 E/mono-rt ( 1549):   at (wrapper native-to-managed) System.Object:798c38f4-8167-4f16-ba11-423a8d31ba4d (intptr,intptr,int,int)



Happens on either the emulator, or physical device.
I just installed 2.0.1.6492-pre1 to test (was 2.0.1.6490)


This code was working in 2.0.0.6484, I will also try downgrading if the prerelease does not work. Will post results.
Comment 14 Jason Couture 2016-01-07 14:01:25 UTC
Prerelease broke build, downgraded to 6484, but still didn't work. Must be a Xamarin.Android issue. The WebView on my emulator is the same as the one I've been testing with. Current Versions:
Xamarin: 4.0.0.1717
Xamarin.Android: 6.0.0.35
Xamarin.iOS: 9.3.99.33


I don't know what version of Xamarin i'm on, but I update regularly. Last time I worked on this project was late November, early December.
Comment 15 Jason Couture 2016-01-07 14:03:14 UTC
Correction: I don't know what version I was on.

I'm going to override the platform renderer and try the cache stuff suggested. Will post results when I do.
Comment 16 Jason Couture 2016-01-07 14:17:26 UTC
Disabling hardware acceleration does not help. Disabling cache did not help for me either.

I tried this renderer:

[assembly: ExportRenderer(typeof(WebView), typeof(CustomWebViewRenderer))]
....
    public class CustomWebViewRenderer : WebViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                Control.ClearCache(true);
                Control.Settings.CacheMode = CacheModes.NoCache;
            }
        }
    }




Crash logcat:
01-07 09:12:46.175 E/chromium( 2226): ### WebView Version 40 (1808730-x86) (code 400007)
An unhandled exception occured.

referenceTable GDEF length=814 1
referenceTable GSUB length=11364 1
referenceTable GPOS length=47302 1
referenceTable head length=54 1
01-07 09:12:48.903 E/mono    ( 2226): 
01-07 09:12:48.903 E/mono    ( 2226): Unhandled Exception:
01-07 09:12:48.903 E/mono    ( 2226): System.NullReferenceException: Object reference not set to an instance of an object
01-07 09:12:48.903 E/mono    ( 2226):   at System.Threading.WaitHandle.WaitOne (Int32 millisecondsTimeout, Boolean exitContext) [0x00056] in /Users/builder/data/lanes/2512/d3008455/source/mono/mcs/class/corlib/System.Threading/WaitHandle.cs:381 
01-07 09:12:48.903 E/mono    ( 2226):   at System.Threading.WaitHandle.WaitOne (Int32 millisecondsTimeout) [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/mcs/class/corlib/System.Threading/WaitHandle.cs:388 
01-07 09:12:48.903 E/mono    ( 2226):   at System.Threading.Timer+Scheduler.SchedulerThread () [0x00257] in /Users/builder/data/lanes/2512/d3008455/source/mono/mcs/class/corlib/System.Threading/Timer.cs:395 
01-07 09:12:48.903 E/mono    ( 2226):   at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00017] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/threading/thread.cs:68 
01-07 09:12:48.903 E/mono    ( 2226):   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, Boolean preserveSyncCtx) [0x00081] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/threading/executioncontext.cs:581 
01-07 09:12:48.903 E/mono    ( 2226):   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, Boolean preserveSyncCtx) [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/threading/executioncontext.cs:530 
01-07 09:12:48.903 E/mono    ( 2226):   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x00031] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/threading/executioncontext.cs:519 
01-07 09:12:48.903 E/mono    ( 2226):   at System.Threading.ThreadHelper.ThreadStart () [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/threading/thread.cs:105 
01-07 09:12:48.903 E/mono-rt ( 2226): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
01-07 09:12:48.903 E/mono-rt ( 2226):   at System.Threading.WaitHandle.WaitOne (Int32 millisecondsTimeout, Boolean exitContext) [0x00056] in /Users/builder/data/lanes/2512/d3008455/source/mono/mcs/class/corlib/System.Threading/WaitHandle.cs:381 
01-07 09:12:48.903 E/mono-rt ( 2226):   at System.Threading.WaitHandle.WaitOne (Int32 millisecondsTimeout) [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/mcs/class/corlib/System.Threading/WaitHandle.cs:388 
01-07 09:12:48.903 E/mono-rt ( 2226):   at System.Threading.Timer+Scheduler.SchedulerThread () [0x00257] in /Users/builder/data/lanes/2512/d3008455/source/mono/mcs/class/corlib/System.Threading/Timer.cs:395 
01-07 09:12:48.903 E/mono-rt ( 2226):   at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00017] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/threading/thread.cs:68 
01-07 09:12:48.903 E/mono-rt ( 2226):   at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, Boolean preserveSyncCtx) [0x00081] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/threading/executioncontext.cs:581 
01-07 09:12:48.903 E/mono-rt ( 2226):   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, Boolean preserveSyncCtx) [0x00000] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/threading/executioncontext.cs:530 
01-07 09:12:48.903 E/mono-rt ( 2226):   at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x00031] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/threading/executioncontext.cs:519 
01-07 09:12:48.903 E/mono-rt ( 2226):   at System.Threading.ThreadHelper.ThreadStart () [0x0000b] in /Users/builder/data/lanes/2512/d3008455/source/mono/external/referencesource/mscorlib/system/threading/thread.cs:105
Comment 17 Jason Couture 2016-01-07 14:44:33 UTC
Running without the debugger causes the issue to go away, for now.
I'll see what else I can find to help.
Comment 18 John Hardman 2016-03-24 14:40:09 UTC
Using 2.1.0.6529, I get an exception every time I run on Android using a debugger.

Without the debugger, the debug build runs fine.

Note that my stack trace is different from that shown above, but the effect is the same - impossible to debug anything around WebView.
Comment 19 Jonathan Pryor 2016-03-24 17:22:46 UTC
@Grendel: Comment #17 and Comment #18 sound like dupes of Bug #35798.
Comment 20 Marek Habersack 2016-04-11 14:53:10 UTC
This bug is a combination of a bug condition in ART (fixed in the newer versions of it, although not completely, details below) and of the way Mono debugging on Android works.

Mono uses SIGSEGV to implement single-stepping (before anyone asks - this is a good way to jump out of managed code into the native one - the segfault handler takes over and proceeds accordingly) which, unfortunately, clashes with the segfault handler inside ART. The ART handler attempts to be smart and avoid nested segfaults in *Java* generated code. It does that by unhooking ART signal handler when running generated code and restoring the original handler for the duration of the generated code run, then plugging its own handler back in. This bug is triggered by an assumption in ART that the segfault handler will *always* be swapped out while Java generated code runs, which is obviously not the case with Xamarin.Android. The buggy version thus calls the ART handler initialization *twice* and thus the assertion which is the subject of this bug. Newer versions of ART (I checked master) fix the issue almost completely - they just leave a very tiny race condition which *may* be hit by Mono sometimes. Unfortunately, I don't see a way to fix that race condition in ART so we'll have to live with it (but do read on).

The workaround (and a long-term fix for the issue) is to use software breakpoints implemented by the Mono runtime. Those breakpoints don't use the SIGSEGV mechanism but instead inject CPU-specific code to single-step. Transitioning to software breakpoints is a long-term goal for the Mono runtime on the supported platforms. Unfortunately, there is a bug in the currently released versions of Mono which makes the software breakpoints fail on Linux and ARM machines - thus on Android. 

All of the issues we found with the software breakpoints are fixed in the upcoming Cycle 7 Xamarin.Android alpha. This release will default to software breakpoints so you should no longer see the assertion and you should be able to debug your applications without issues.

If you do see the assertion, however, it probably means that some other native code mapped into the Xamarin.Android app segfaults and triggers the assertion.

Note You need to log in before you can comment on or make changes to this bug.