Bug 49168 - App crashes when navigating to page with ControlTemplate
Summary: App crashes when navigating to page with ControlTemplate
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-12-07 06:47 UTC by Konstantin
Modified: 2017-05-24 22:26 UTC (History)
14 users (show)

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

Sample sln demonstrating bug (94.65 KB, application/zip)
2017-01-12 18:49 UTC, Jon Bachelor
Info on my installation of Xamarin Studio, where I have reproduced the issue. (1.81 KB, text/plain)
2017-01-27 23:19 UTC, Jon Bachelor
Application output from LG V20 crash (1.04 KB, text/plain)
2017-01-27 23:20 UTC, Jon Bachelor
Android Device Monitor output for LG V20. (20.73 KB, text/plain)
2017-01-27 23:21 UTC, Jon Bachelor
Application output for Vizio tablet. (68.60 KB, text/plain)
2017-01-27 23:22 UTC, Jon Bachelor
Android Device Monitor output for Vizio tablet. (103.21 KB, text/plain)
2017-01-27 23:22 UTC, Jon Bachelor

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 Konstantin 2016-12-07 06:47:46 UTC
After updating Xamarin.Forms package from to error occurred on devices with Android 6 (on Android 4.4 app works fine). App crashes when navigating to page with ControlTemplate.

java.lang.IllegalStateException: Unable to create layer for BoxRenderer
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Comment 1 adrianknight89 2016-12-07 16:44:01 UTC
Can you update to Service Release 1 and see if the issue still exists?
Comment 2 Konstantin 2016-12-08 11:44:12 UTC
After updating the problem still persists.
Comment 3 Samantha Houts [MSFT] 2016-12-08 18:09:46 UTC
Thank you for taking the time to submit the bug. We tried to reproduce the issue you reported but were unable given the description. If you could please attach a reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue, we would very much appreciate it.  
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d  
Warm regards, 
Xamarin Forms Team
Comment 4 Konstantin 2016-12-14 13:24:42 UTC
Sorry for my late reply. I was wrong in the cause of the error.
App crashes when ActivityIndicator's visibility change to true.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="DemoBug.View.MainView"
        <ContentPresenter Content="{TemplateBinding Content}"/>
        <Grid IsVisible="{Binding BindingContext.IsGridVisible, Source={x:Reference root}}">
          <BoxView BackgroundColor="Black"
          <StackLayout VerticalOptions="Center">
            <ActivityIndicator IsRunning="{Binding BindingContext.IsGridVisible, Source={x:Reference root}}"/>
            <Label Text="Loading..."

  <Button Text="Click me"
          Command="{Binding ShowGridCommand}"/>

Comment 5 Jon Bachelor 2017-01-12 18:49:58 UTC
Created attachment 19315 [details]
Sample sln demonstrating bug

This sample app runs fine on iOS, but will show the bug when run on Android. Steps to reproduce:
1) Run app on Android (we tested on API 23)
2) Tap button on main page... App will crash with "Unable to create layer for BoxRenderer" exception. We also tried replacing the BoxView with a Grid, and received the same sort of error (but for a different renderer... 'Platform_DefaultRenderer', I think).
Comment 6 Jon Bachelor 2017-01-12 18:59:13 UTC
One more note to add to Comment 5:

If we remove the BoxView the app will not crash, however the activity indicator is not visible.
Comment 7 Jon Bachelor 2017-01-12 19:28:49 UTC
Another discovery:  It seems like it's completely dependent on the opacity of the BoxView (or Grid, or StackLayout, etc). When we try to set the opacity to any value other than 0 or 1, we get the 'Unable to create layer for.....' error.

Hope this helps...
Comment 8 Samantha Houts [MSFT] 2017-01-25 18:52:06 UTC
Thank you for the additional information and sample app. 

I ran the sample app on my API 21 device and on an API 23 emulator, and I did not experience a crash in either case.

Are you using the latest stable Xamarin.Android (
Comment 9 Jon Bachelor 2017-01-27 23:18:15 UTC
Hi Samantha,

Interesting... I had previously only tried this on real devices. I ran the app on an API 23 emulator, and the app ran just fine.

However, on both physical devices I have with me, the app crashes:
1) Android Vizio tablet, model XR6M10, API 23, Android 6.0.1.
2) LG V20 phone, API 24, Android 7.0

I ran the app on each, and saved the output from both Xamarin's application output window as well as the output from the Android Device Monitor. I also verified that I am indeed using the latest Xamarin.Android (

I'm attaching the following files with all of the above information:
1) XamarinStudioInfo.txt: Details from my machine's Xamarin Studio "about" window.
2) AppOutput_LGV20.txt: Xamarin application output for Vizio tablet.
3) DeviceMonitor_Vizio.txt: Device monitor log for Vizio crash.
4) AppOutput_LGV20.txt: Xamarin application output for LG V20.
5) DeviceMonitor_LGV20.txt: Device monitor log for LG V20 crash.

Hope this helps... Please don't hesitate to let me know if there is any further information I can provide. Thank you!
Comment 10 Jon Bachelor 2017-01-27 23:19:58 UTC
Created attachment 19542 [details]
Info on my installation of Xamarin Studio, where I have reproduced the issue.
Comment 11 Jon Bachelor 2017-01-27 23:20:38 UTC
Created attachment 19543 [details]
Application output from LG V20 crash
Comment 12 Jon Bachelor 2017-01-27 23:21:11 UTC
Created attachment 19544 [details]
Android Device Monitor output for LG V20.
Comment 13 Jon Bachelor 2017-01-27 23:22:03 UTC
Created attachment 19545 [details]
Application output for Vizio tablet.
Comment 14 Jon Bachelor 2017-01-27 23:22:47 UTC
Created attachment 19546 [details]
Android Device Monitor output for Vizio tablet.
Comment 15 Marius Kahmen 2017-02-01 21:10:29 UTC
any updates on this? I deleted all "opacity"-tags/-bindings and it fixed my crashes...

Comment 16 yuan 2017-02-07 10:12:23 UTC
For the XForms is work fine ,but when I update XForms  is crash with "Unable to create layer for BoxRenderer"  ,hope that this bug can be quickly repaired, thanks !
Comment 17 Ashley Gazich [MSFT] 2017-02-07 22:09:22 UTC
I am able to replicate a crash using the sample from Comment 5 on Samsung Galaxy S5, API 23.
Android emulator, iPhone 6, and iOS simulator were OK. 

### Results

v2.3.4.192-pre2 crash
v2.3.3.180 crash
v2.3.3.152-pre2 OK
v2.3.2.127 crash
v2.3.1.114 crash

Java.Lang.IllegalStateException: Unable to create layer for BoxRenderer
  at java.lang.IllegalStateException: Unable to create layer for BoxRenderer
  at at android.os.MessageQueue.nativePollOnce(Native Method)
  at at android.os.MessageQueue.next(MessageQueue.java:323)
  at at android.os.Looper.loop(Looper.java:143)
  at at android.app.ActivityThread.main(ActivityThread.java:7224)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Note: Also tested v2.3.4.192-pre2 and v2.3.3.180 on XS latest Beta, which both exhibited the reported behavior. 

### Version info (latest Stable)
=== Xamarin Studio Enterprise ===

Version 6.1.5 (build 0)
Installation UUID: bbb2aa5e-cc9f-46b8-8fd1-94319df9787c
	Mono 4.6.2 (mono-4.6.0-branch/ac9e222) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406020016

=== NuGet ===


=== Xamarin.Profiler ===

Version: 1.1.8
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.2.1 (11766.1)
Build 8C1002

=== Xamarin.Android ===

Version: (Visual Studio Enterprise)
Android SDK: /Users/ashleyg/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		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)
		5.1    (API level 22)
		6.0    (API level 23)
		7.0    (API level 24)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.3
SDK Build Tools Version: 25.0.2

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:

=== Xamarin Android Player ===

Not Installed

=== Xamarin.iOS ===

Version: (Visual Studio Enterprise)
Hash: 7beaef4
Branch: cycle8-xi
Build date: 2016-12-20 02:58:14-0500

=== Xamarin.Mac ===

Version: (Visual Studio Enterprise)

=== Xamarin Inspector ===

Hash: 1f3067d
Branch: master
Build date: 11/15/2016 4:13:59 PM

=== Build Information ===

Release ID: 601050000
Git revision: 7494718e127af9eaec45a3bd6282d3da927488bd
Build date: 2017-01-17 10:31:01-05
Xamarin addins: c92d0626d347aaa02839689eaac2961d24c9f446
Build lane: monodevelop-lion-cycle8

=== Operating System ===

Mac OS X 10.11.6
Darwin ashleyg.local 15.6.0 Darwin Kernel Version 15.6.0
    Thu Jun 23 18:25:34 PDT 2016
    root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Xamarin Inspector
Comment 18 Magic 2017-02-08 12:05:50 UTC
I have the same issue after I upgraded my project from to

I switched back to the and the issue is gone away.
Comment 19 Chris King 2017-02-16 19:04:51 UTC
I'm unable to reproduce the crash on v2.3.3.180 on my LGE Nexus 5.
Comment 20 Chris King 2017-02-16 19:44:48 UTC
Although I don't have a device which reproduces this issue https://xamarinhq.slack.com/team/ashley does. So we can reach out to her to get details when we start looking at this issue.
Comment 21 Jimmy [MSFT] 2017-05-24 22:26:01 UTC
This appears to be similar to or a duplicate of bug 51238.

I was able to reproduce this issue on my Android 6.0 device with Forms However after updating to Forms the app is no longer crashing.