We are facing random crash in Flex Layout with null reference exception in the xamarin forms version 4.4
don't crash
Crashes the app randomly but more frequently
STACK TRACE
FlexLayout.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint)
StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders)
StackLayout.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint)
VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags)
ScrollView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height)
Layout.UpdateChildrenLayout ()
Layout.OnSizeAllocated (System.Double width, System.Double height)
VisualElement.SizeAllocated (System.Double width, System.Double height)
Layout.ResolveLayoutChanges ()
Thread+RunnableImplementor.Run ()
IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
@Srikanth540-L Can you please attach a small project that demonstrates this issue? Thanks!

FlexLayout Crash related code:
@samhouts Please refer the zip file for code related to crash
FlexLayoutXamlCode.zip
Crash Scenario:
As shown in the above screen shot we have a list view right below FlexLayout( which holds list of various category buttons as filters ) when we do pull to refresh on list view, if the token expires we are making an api call to get the fresh token followed fetching the latest data during this process the page refreshes and the OnCoursesResult method will get this to bind the fresh data.
The app crashes randomly in the above mentioned scenario
Note: Crash happens more frequently when the app is left idle for a long time and then doing pull to refresh
@Srikanth540-L I'd love to be able to reproduce this, but I can't do that easily with the code snippet provided. Can you tell me if this is new in 4.4 and did not crash in a prior version? I see some opportunities for null checks in that method, but this seems indicative of a larger issue. Thanks!
@samhouts the flex layout for the filter is implemented after the xamarin forms update to 4.4, we are not sure about prior versions, the line where we are clearing RegisteredCategories it cannot be null since we are initializing in constructor and I can tell you that there are no other places where it is set to null, I have shared code that is specific to Flex Layout as of now I am limited to share complete business logic code for the above crash.
Thank you!
@Srikanth540-L We do know that there are some quirks with FlexLayout when used in combination with other Layouts. They do not always work well together. If you can think of a different way to do this complex layout, that might be a good way to go. In the meantime, we'll investigate the null references. Thanks!
I looked at the code, and there's a possibility, due to a race condition, that GetFlexItem returns null and causes the exception. @Srikanth540-L I could generate a nuget (based on 4.4 or 4.5) with the fix attempt if you're ok to try it
@StephaneDelcroix We have replaced flex layout with collectionview since then there is no such crash 聽has occurred, so we are good with it , Anyhow we would like try the nuget on 4.4 to test it.
Thanks!
@Srikanth540-L
@StephaneDelcroix tested the nuget it's working fine , We haven't noticed any crash.So closing the issue.
Thanks!
@Srikanth540-L
reopening, as I haven't send the PR for the said nuget
Most helpful comment
@samhouts the flex layout for the filter is implemented after the xamarin forms update to 4.4, we are not sure about prior versions, the line where we are clearing RegisteredCategories it cannot be null since we are initializing in constructor and I can tell you that there are no other places where it is set to null, I have shared code that is specific to Flex Layout as of now I am limited to share complete business logic code for the above crash.
Thank you!