Bug 34036 - NullReferenceException with certain layout
Summary: NullReferenceException with certain layout
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.5.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-09-17 14:10 UTC by Tomasz Wiśniewski
Modified: 2016-04-13 19:17 UTC (History)
5 users (show)

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

Test case (6.88 MB, application/octet-stream)
2015-09-17 14:12 UTC, Tomasz Wiśniewski

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 Tomasz Wiśniewski 2015-09-17 14:10:28 UTC
When we have a certain layout we can get a null reference exception from Grid.LayoutChildren.

I created simple app which shows the issue. To reproduce the bug:
1. Start attached app.
2. Click "GO" button. You should get an exception.

With the provided app exception happens to me every time.

Exception is thrown because of the layout of the SecondPage.xaml. I tried to created the simplest layout possible that throws this exception, so every element here is important as I described in the comments in SecondPage.xaml file. From what I noticed it has something to do with measuring element in StackLayout.

Issue also happens with more complex layouts or with other controls (I tried Images instead of Labels). However with other layouts it seems to happen seldom and randomly.

This bug didn't appear in 1.5 version, it was present before, I'm not sure from which version.

Stack trace:

System.NullReferenceException: Object reference not set to an instance of an object
at Xamarin.Forms.Grid.LayoutChildren (double,double,double,double) <IL 0x000c9, 0x00660>
at Xamarin.Forms.Layout.UpdateChildrenLayout () <IL 0x000c7, 0x00773>
at Xamarin.Forms.Layout.OnSizeAllocated (double,double) <IL 0x00010, 0x000bb>
at Xamarin.Forms.VisualElement.SizeAllocated (double,double) <IL 0x00003, 0x00083>
at Xamarin.Forms.Layout.OnChildMeasureInvalidated () <IL 0x00077, 0x003bf>
at Xamarin.Forms.Layout.OnChildMeasureInvalidated (object,System.EventArgs) <IL 0x00001, 0x00057>
at Xamarin.Forms.VisualElement.InvalidateMeasure () <IL 0x00014, 0x00083>
at Xamarin.Forms.StackLayout.InvalidateMeasure () <IL 0x00017, 0x000db>
at Xamarin.Forms.VisualElement/<>c.<.cctor>b__186_8 (Xamarin.Forms.BindableObject,object,object) <IL 0x00006, 0x00083>
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty,Xamarin.Forms.BindableObject/BindablePropertyContext,object,bool,Xamarin.Forms.BindableObject/SetValueFlags,bool) <IL 0x00111, 0x00787>
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty,object,Xamarin.Forms.BindableObject/SetValueFlags,Xamarin.Forms.BindableObject/SetValuePrivateFlags) <IL 0x00154, 0x008f7>
at Xamarin.Forms.BindingExpression.ApplyCore (object,Xamarin.Forms.BindableObject,Xamarin.Forms.BindableProperty,bool) <IL 0x00212, 0x010ff>
at Xamarin.Forms.BindingExpression.Apply (bool) <IL 0x00048, 0x001cb>
at Xamarin.Forms.BindingExpression/BindingExpressionPart.<PropertyChanged>b__38_0 () <IL 0x00007, 0x00053>
at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/2058/58099c53/source/monodroid/src/Mono.Android/platforms/android-22/src/generated/Java.Lang.IRunnable.cs:71
at (wrapper dynamic-method) object.f00a9897-946c-4966-ba1f-db218bd50d4e (intptr,intptr) <IL 0x00011, 0x0003b>
Comment 1 Tomasz Wiśniewski 2015-09-17 14:12:17 UTC
Created attachment 12930 [details]
Test case