Bug 54717 - System.NullReferenceException Xamarin.Forms.Platform.Android.PlatformConfigurationExtensions.OnThisPlatform[T] (T element)
Summary: System.NullReferenceException Xamarin.Forms.Platform.Android.PlatformConfigur...
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.4
Hardware: PC Windows
: Normal major
Target Milestone: ---
Assignee: Stephane Delcroix
Depends on:
Reported: 2017-04-07 10:26 UTC by jerone
Modified: 2017-06-29 10:09 UTC (History)
9 users (show)

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

Reproducable project (98.51 KB, application/x-zip-compressed)
2017-04-09 17:41 UTC, jerone

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 jerone 2017-04-07 10:26:41 UTC
When upgrading to XF our app stopped working completely. There was no issue when run with XF

No visual exception throw. Only in logcat we found the following exception being thrown:

Time	Device Name	Type	PID	Tag	Message
04-07 11:36:28.345	 5.7" Marshmallow (6.0.0) XHDPI Phone	Info	2975	MonoDroid	System.NullReferenceException: Object reference not set to an instance of an object.
  at Xamarin.Forms.Platform.Android.PlatformConfigurationExtensions.OnThisPlatform[T] (T element) [0x00000] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\PlatformConfigurationExtensions.cs:8 
  at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnResume () [0x00006] in C:\BuildAgent\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:235 
  at Android.App.Activity.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in /Users/builder/data/lanes/4468/b16fb820/source/monodroid/src/Mono.Android/platforms/android-25/src/generated/Android.App.Activity.cs:4191 
  at (wrapper dynamic-method) System.Object:2ef5ac0f-cae6-429e-acb2-8011b5d3b507 (intptr,intptr)

After some digging we found the root of our crash; which was the following code in our XAML contentpage view:
		<x:Array x:Key="SomeColors" Type="{x:Type Color}">
			<x:StaticResource Key="Color1" />
			<x:StaticResource Key="Color2" />

`<x:StaticResource>` reference to some resources (Color1 & Color2) we have defined in our `app.xaml`.
We needed an `x:Array` combined with a custom converter to select a color based on a condition.
My guess is that it doesn't appear to be related to `<x:Array>`, but to `<x:StaticResource>` within the `<ContentPage.Resources>` in a contentpage.

All our XAML is compiled (`[assembly: XamlCompilation(XamlCompilationOptions.Compile)]`).

I have to stress that above code worked perfectly in XF and I can't find any issue related to this pointing out about a breaking change.
Comment 1 Paul DiPietro [MSFT] 2017-04-07 14:51:22 UTC
What have you tried to do to remedy the issue thus far? Have you attempted to wipe the bin/obj folders, remove the app from the emulator/device, and rebuild the solution itself? If you've done all of those things and are still experiencing the issue, can you reliably reproduce it in a separate project (with minimal code necessary) and provide it to us?
Comment 2 jerone 2017-04-09 17:41:19 UTC
Created attachment 21365 [details]
Reproducable project

Attached is a zipped folder, contains two identical projects for reproducing this bug:
* XF_bug_54717_A is a working project with XF
* XF_bug_54717_B is a breaking project with XS

The failing file is `XF_bug_54717\Views\HomeView.xaml`, lines 10 and 11.
Comment 3 jerone 2017-04-09 17:43:43 UTC
And yes, I wiped the bin/obj folders, removed the app form the emulator/device, rebuild/cleaned the solution, updated packages. The issue reproducible on 3 computers (all Windows 10 Pro x64).
Comment 4 jerone 2017-04-09 17:58:05 UTC
Steps to reproduce:
1. Download above attachment.
2. Open project XF_bug_54717_A.
3. Restore packages.
4. Start Android project.
5. See home view with "Hello World" text.
6. Open project XF_bug_54717_B.
7. Restore packages.
8. Start Android project.
9. See NO home view, only a white empty screen.
Comment 5 Tma 2017-04-10 15:13:46 UTC
I met the same issue. When I tried to start my custom activity through intent and get my app crush. I have added try/catch in custom activity. It is kind of working for me now.

protected override  void OnResume()
            catch (Exception)
                // ignored
Comment 6 jerone 2017-04-12 18:15:32 UTC
@PaulDiPietro Can you reproduce it with attached project? Do I have to deliver something else?
Comment 7 Paul DiPietro [MSFT] 2017-04-13 15:20:16 UTC
Yes, it seems like there's some kind of regression between the two versions and it occurs on the nightly build as well, but will require further investigation.
Comment 8 Chris King 2017-04-17 17:54:48 UTC
Verified the bug. Pinged Stephane. Regression is so old it would be extra painful to do a bisection; regression introduced before nightly builds.
Comment 9 Stephane Delcroix 2017-04-19 13:05:03 UTC
Comment 10 Samantha Houts [MSFT] 2017-04-27 19:39:42 UTC
Should be fixed in 2.3.5 stable. Thank you!
Comment 11 Saurabh Paunikar 2017-06-29 10:09:00 UTC
Fixed verified on 
Xamarin.Forms version 2.3.5-pre5

Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01586

Installed Version: Enterprise

Xamarin (de55d19)
Xamarin.Android (f6289cd)
Xamarin.iOS (494fcbc)