Bug 44910 - [iOS] StackLayout.Childer.Add crashes when adding children to an empty StackLayout in OnAppearing
Summary: [iOS] StackLayout.Childer.Add crashes when adding children to an empty StackL...
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.1.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-09-30 07:48 UTC by Thibault Durand
Modified: 2016-10-14 07:13 UTC (History)
3 users (show)

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

Solution for reproduction, including git history (200.58 KB, application/zip)
2016-09-30 07:48 UTC, Thibault Durand

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 for Bug 44910 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

Description Thibault Durand 2016-09-30 07:48:28 UTC
Created attachment 17819 [details]
Solution for reproduction, including git history


In Page.OnAppearing, adding children to a StackLayout that was previously empty (and thus had a width and height of zero) causes a NullReferenceException in Xamarin.Forms.StackLayout.AlignOffAxis. 

This bug is a regression introduced by: Xamarin.Forms.
Latest working stable version: Xamarin.Forms.

**Steps to Reproduce**

   1. Run the attached sample on iOS (tested on simulator, but same issue on device)
   2. Tack any of the two buttons on the welcome page

**Actual Results**

The application crashed.

**Expected Results**

Should show the expected page with Label + Switch at the bottom of the page. 

**Build Date & Platform**

   Mac OS X 10.11.6
   Xamarin Studio 6.0.2 (build 73)
   Runtime:Mono 4.4.2
   XCode 7
   iPhone Simulator 9.3.5


The attached archive contains a git repository allowing you to test with the latest working version and the first crashing version.
Comment 1 adrianknight89 2016-10-01 06:46:40 UTC
See https://github.com/xamarin/Xamarin.Forms/pull/408
Comment 2 adrianknight89 2016-10-13 20:50:30 UTC
Thibault, please see my comments on GitHub. This seems to be a problem with horizontallayoutoptions and padding (only top or bottom) being set at the same time when the page is pushed on the navigation stack. Seems like layout calculations are messing up.

I made some changes to StackLayout so that it doesnt crash. Instead, it calculates layout to proceed.
Comment 3 Thibault Durand 2016-10-14 07:13:55 UTC
Hi Adrian, 

Thank you for your PR and comments on this issue.
I apologize for not being very engaged in the folluw-up of this issue: The main reason is that I found a work-around (not modify the StackPanel in OnAppearing) and reported this issue only after I published my app with the work-around. 
So my report was more for the Xamarin team to be aware of this regression rather than to get a fix ASAP. 

The other reason is that I'm not very used to contributing to open-source projects and I don't really know where to start. Since this discussion is not relevant for this issue I've contacted you via PM on the forums.