Bug 44538 - Random NRE on button click
Summary: Random NRE on button click
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.1
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Paul DiPietro [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-09-20 18:51 UTC by David
Modified: 2017-06-19 18:57 UTC (History)
6 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 David 2016-09-20 18:51:23 UTC
I have a Xamarin Forms app that works fine on iOS and throws a NRE when I click on a button that changes pages in Android.

StackTrace:
===============================================================
System.NullReferenceException: Object reference not set to an instance of an object.
  at Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Platform.Android.IPlatformLayout.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00017] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:198
  at Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout (System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x0000e] in C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\PlatformRenderer.cs:73
  at Android.Views.ViewGroup.n_OnLayout_ZIIII (System.IntPtr jnienv, System.IntPtr native__this, System.Boolean changed, System.Int32 l, System.Int32 t, System.Int32 r, System.Int32 b) [0x00009] in /Users/builder/data/lanes/3511/0e59c362/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views.ViewGroup.cs:3427
  at at (wrapper dynamic-method) System.Object:f5b58111-070b-4cca-97f5-1cced5aed1b0 (intptr,intptr,bool,int,int,int,int)
===============================================================


Xamarin Studio Environment Details:
===============================================================
Xamarin Studio Community
Version 6.1 (build 5441)
Installation UUID: 2bc5a42e-416b-4731-9d4a-3c9a524c4250
Runtime:
	Mono 4.6.0 (mono-4.6.0-branch/746756c) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406000245

NuGet
Version: 3.4.3.0

Xamarin.Profiler
Not Installed

Apple Developer Tools
Xcode 8.0 (11246)
Build 8A218a

Xamarin.iOS
Version: 10.0.0.6 (Xamarin Studio Community)
Hash: 6c3fee4
Branch: xcode8
Build date: 2016-09-09 13:01:32-0400

Xamarin.Android
Version: 7.0.0.18 (Xamarin Studio Community)
Android SDK: /Users/toadzky/Library/Android/sdk
	Supported Android versions:
		6.0 (API level 23)

SDK Tools Version: 25.1.7
SDK Platform Tools Version: 24.0.0
SDK Build Tools Version: 24.0.0 rc4

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

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Xamarin Android Player
Not Installed

Xamarin.Mac
Not Installed

Build Information
Release ID: 601005441
Git revision: 68292d1ab289911c815ddc715dd7cc29a9752f9f
Build date: 2016-09-09 04:43:23-04
Xamarin addins: ed25d008672663eeb9db55f1ccecb3c24d2fd3b2
Build lane: monodevelop-lion-cycle8

Operating System
Mac OS X 10.11.6
Darwin skytag.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
Addin Maker 1.3.2
WakaTime 2.0.2
Prism Template Pack 1.3
Redth's Addins 1.0.2
JSON Copy 1.1
XamlStyler 1.0.1
Manifest.addin 0.0.0.0
========================================================================
Comment 1 David 2016-09-20 19:19:10 UTC
If it helps, this is happening when I'm transitioning to a page with a customized MapView, and the page is created just fine. The app/MVVM framework doesn't make it to creating my view model after the page has been created though.
Comment 2 David 2016-09-20 19:39:25 UTC
Correction, my view model is created as part of the `InitializeComponent` call in the page constructor.
Comment 3 Paul DiPietro [MSFT] 2016-09-26 16:09:46 UTC
A reproduction would be very helpful here if you can provide one.
Comment 4 David 2016-09-28 23:14:32 UTC
I'll do my best to get you one when I have a chance.

It's definitely related to some kind of location permissions issue and the map view. It never asked me for permissions and I thought it already had permissions, but once I manually (via app settings) gave the app permissions for location updates, it stopped crashing.

I managed to get an error related to location permissions once I commented out my map view from the xaml. Then, after granting permissions and making sure it would load the page, I un-commented the map view and it still works. Confirmed on both physical device and emulator.

I was using James M.'s Permissions plugin, and I made a mistake when checking permissions to see if they were allowed/denied. The documentation for his "PermissionStatus" enum led me to believe that "Denied" would be the state for only if the user had explicitly denied the permission. It turns out that it's also the default state of a permission that has never been requested. So I wasn't ever asking for permission.
Comment 5 Paul DiPietro [MSFT] 2017-06-19 18:57:24 UTC
This issue will be closed due to a lack of updates or provided reproductions, so we can reasonably assume it is no longer an issue. Please reopen this and attach a minimized reproduction project if the issue still exists as of the latest prerelease or nightly build.