NullReferenceException on Grid.CalculateAutoCells [Only XF iOS]

SteeBonoSteeBono ITMember ✭✭

Hi,

I'm developing an app with Xamarin Forms from 7 months.
My app worked very well.
I have done 1 month on Android side, because I fixed some bugs and added some features.

Today I have ported these mods on iOS side and now I have a NullReferenceException on Grid, when I scroll the List View. (On Android all works perfectly)

Here's what happens:
- I open the page that contains the list
- The list is loaded and displayed correctly
- If I try to scroll through the list, appears this exception

Stack Trace:

at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x00357] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\GridCalc.cs:144 at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0000c] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\GridCalc.cs:483 at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0000e] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\GridCalc.cs:17 at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x000c7] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:229 at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:194 at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:629 at Xamarin.Forms.Layout+<>c.<OnChildMeasureInvalidated>b__39_0 () [0x00080] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:332 at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/Foundation/NSAction.cs:163 at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/UIKit/UIApplication.cs:79 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3969/44931ae8/source/xamarin-macios/src/UIKit/UIApplication.cs:63 at MusiDownPortable.iOS.Application.Main (System.String[] args) [0x00008] in /Users/steebono/SourceTree/musidown/MusiDownPortable/MusiDownPortable/MusiDownPortable.iOS/Main.cs:17

Sometimes scroll works but when I try to reload list I have this exception:

Second StackTrace:

at Xamarin.Forms.Grid.GetLastAutoColumn (Xamarin.Forms.BindableObject child) [0x00016] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\GridCalc.cs:657 at Xamarin.Forms.Grid.ExpandLastAutoColumnIfNeeded (System.Double width, System.Boolean expandToRequest) [0x00024] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\GridCalc.cs:331 at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0013a] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\GridCalc.cs:520 at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0000e] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\GridCalc.cs:17 at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x000c7] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:229 at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:194 at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\VisualElement.cs:629 at Xamarin.Forms.Layout+<>c.<OnChildMeasureInvalidated>b__39_0 () [0x00080] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\Layout.cs:332 at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/Foundation/NSAction.cs:163 at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIApplication.cs:79 at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIApplication.cs:63 at MusiDownPortable.iOS.Application.Main (System.String[] args) [0x00008] in /Users/steebono/SourceTree/musidown/MusiDownPortable/MusiDownPortable/MusiDownPortable.iOS/Main.cs:17

XAML Code:

<ListView x:Name="listView" ItemSelected="OnItemSelected" IsVisible="False" HasUnevenRows="False" RowHeight="50" IsPullToRefreshEnabled="True" Refreshing="mySongs_OnRefreshing"> <x:Arguments> <ListViewCachingStrategy>RecycleElement</ListViewCachingStrategy> </x:Arguments> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <ViewCell.ContextActions> <MenuItem Clicked="mySongDelete_OnClicked" CommandParameter="{Binding .}" Text="Delete" IsDestructive="True" /> </ViewCell.ContextActions> <Grid> <Grid.RowDefinitions> <RowDefinition Height="50" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="5" /> <ColumnDefinition Width="35" /> <ColumnDefinition Width="*" /> <ColumnDefinition Width="35" /> <ColumnDefinition Width="5" /> </Grid.ColumnDefinitions> <ff:CachedImage Source="{Binding FavoriteIcon}" CacheDuration="1" RetryCount="1" Aspect="AspectFit" HorizontalOptions="StartAndExpand" Grid.Row="0" Grid.Column="1"> <ff:CachedImage.GestureRecognizers> <TapGestureRecognizer Tapped="onClick_Favorite"/> </ff:CachedImage.GestureRecognizers> </ff:CachedImage> <Label Text="{Binding Title}" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" VerticalTextAlignment="Center" HorizontalTextAlignment="Center" LineBreakMode="TailTruncation" FontSize="Medium" Grid.Row="0" Grid.Column="2" /> <ff:CachedImage Source="{Binding MenuIcon}" CacheDuration="1" RetryCount="1" Aspect="AspectFit" HorizontalOptions="EndAndExpand" Grid.Row="0" Grid.Column="3"> <ff:CachedImage.GestureRecognizers> <TapGestureRecognizer Tapped="onClick_Menu"/> </ff:CachedImage.GestureRecognizers> </ff:CachedImage> </Grid> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>

C# Code:

Inside OnAppearing():

`

// Other code here

listView.ItemSource = _myListItems;

// Other code here

`

My List is declared as:

`

private ObservableCollection<MyItemEntry> _myListItems = new ObservableCollection<MyItemEntry>();

`

MyItemEntry object is a class derived from INotifyPropertyChanged

I have an event that load and reload the list if needed:

`

        // Other code here

        // Start async operation
                Task.Run(() =>
                {
                    // Clear List
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        if (_myListItems.Any()) _myListItems.Clear();
                    });
                    // Get refreshed list.
                    var myList = DependencyService.Get<IItemHandler>().ReadItem;

                    if (myList.Any())
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            foreach (var itemDataEntry in myList)
                            {
                var menuIcon = "Menu100.png";
                                var favoriteIcon = itemDataEntry.Favorite ? "Favfill.png" : "Fav100.png";
                                _myListItems.Add(new MyItemEntry
                                {
                                    FavoriteIcon = favoriteIcon,
                                    MenuIcon = menuIcon,
                                    Title = decSong
                                });
                            }
                            if (_mySongsItems.Any())
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    listView.IsVisible = true;
                                    loadingIndicator.IsVisible = false;
                                    loadingIndicator.IsRunning = false;
                                    layoutDataInfo.IsVisible = false;
                                    lbDataInfo.IsVisible = false;
                                });
                            }
                            else
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    listView.IsVisible = false;
                                    loadingIndicator.IsVisible = false;
                                    loadingIndicator.IsRunning = false;
                                    layoutDataInfo.IsVisible = true;
                                    imgDataInfo.IsVisible = true;
                                    lbDataInfo.IsVisible = true;
                                });
                            }
                        });
                    }
                    else
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            listView.IsVisible = false;
                            loadingIndicator.IsVisible = false;
                            loadingIndicator.IsRunning = false;
                            layoutDataInfo.IsVisible = true;
                            imgDataInfo.IsVisible = true;
                            lbDataInfo.IsVisible = true;
                        });
                    }
                });

// Other code here for update list if needed

`

This codes on Android work perfectly. On iOS this codes work perfectly but if i try to scroll the list, I have that Exception.

A important thing is that this Event do not fire when I scroll the List.
I think that my code is not the cause of this Exception, because this happend only if I scroll
If I open the page and after do nothing, all work perfectly. I do not manage in any way scrolling or similar.

I have viewed the code of Xamarin Libraries and seems That Grid.ColumnDefinitions at some point became null.

First StackTrace say:

at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x00357] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\GridCalc.cs:144

In this line there is a for cycle:

for (var i = 0; i < _columns.Count; i++)

Second StackTrace say:

at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x00357] in C:\BuildAgent2\work\ca3766cfc22354a1\Xamarin.Forms.Core\GridCalc.cs:657

In this line there is a if with same variable of first stacktrace:
if (_columns[i].Width.IsAuto)

so I think that the null reference exception is caused by _columns var.
As you can see in my xaml code I have set ColumnDefinitions.

This error happens when the list has already been created and displayed so.. someone set this to null at some point or Layout.UpdateChildrenLayout fails to get ColumnDefinitions value?

Another observation is that I set ItemSource of listView inside OnAppearing method; when I reload page, I clear my list object and I re-insert all updated items to list. But I think that this is not a problem because my list's items derived from INotifyPropertyChanged and my list is a ObservableCollecion list.

Xamarin Mac Env: last version iOS: 10.1 Xamarin Forms: 2.3.3.168 / 2.3.3.180 (Tried both)

Sorry for my english.

Thanks,
Stefano

Posts

  • SteeBonoSteeBono ITMember ✭✭

    UPDATE:

    To make more specific tests, I imported the Xamarin Forms projects in my project.

    After a rebuild, I have debugged app and app stack here:

    As you can see, the var _columns is null.
    So I added some Log inside Xamarin.Forms projects and this is the result:
    (Here you can see the last piece of log before the exception)

    [InvalidateMeasureInternal] init _columns to null... <-- (X1 Step) [InvalidateMeasureInternal] _columns to null initialized. <-- (end X1 Step) [InvalidateMeasureInternal] init _columns to null... <-- (X2 Step) [EnsureRowsColumnsInitialized] _columns initialize.. <-- Init to value because X1 Step init _columns to null [EnsureRowsColumnsInitialized] _columns initialized. [AssignAbsoluteCells] access to _columns. [CalculateAutoCells] access to _columns. [CalculateAutoCells] access to _columns. [InvalidateMeasureInternal] _columns to null initalized. <-- (end X2 Step) [MeasureGrid] access to _columns. <-- here _columns is null! Because X2 Step has init _columns to null in delay [ContractColumnsIfNeeded] access to _columns. Thread finished: <Thread Pool> #6

    I do not know if you understood what I mean :sweat_smile:

    What can be the cause?

  • JimmyGarridoJimmyGarrido USXamarin Team Xamurai

    I created a sample project based on the code you provided but I wasn't able to reproduce the issue. Can you attach a complete and minimal reproduction project so I can look into this some more? Thanks!

  • SteeBonoSteeBono ITMember ✭✭

    Hi,

    From what I understand, it happens if you have a Grid Element in a AbsoluteLayout.

    Because each time an item is updated, inside an AbsoluteLayout triggers the event ChildOnPropertyChanged.
    If Grid element is refreshed too faster in small time, can happen that while Xamarin.Forms.Core use the variable '_columns' inside UpdateChildrenLayout, the method InvalidateMeasureInternal can set _columns to null.

    void ChildOnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == LayoutFlagsProperty.PropertyName || e.PropertyName == LayoutBoundsProperty.PropertyName) { InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged); UpdateChildrenLayout(); } }

    This is my guess.

    Anyway when I go to home I will upload a test project.

    Thanks for reply,
    Stefano

  • Deepesh.6704Deepesh.6704 INMember

    @SteeBono ... I'm facing the same issue but on the _rows column and on android (works fine on iOS). Were you able to find a fix?

  • SteeBonoSteeBono ITMember ✭✭

    @Deepesh.6704 said:
    @SteeBono ... I'm facing the same issue but on the _rows column and on android (works fine on iOS). Were you able to find a fix?

    Hi, if I remember correctly the problem was caused by a too fast update of the items in the list.
    Now I'm using FastCell dev by GeorgeCook.

    I recommend you, because they are really fast.
    In addition to this, I also decided to load the items of list in groups instead of loading them individually.

    Example:

    `

    protected override void OnAppearing()
        {
            base.OnAppearing();
    
        listView.ItemsSource = _myListItems;
    }
    public void updateListFunction()
    {
        var y = SomeThing.GetListFromUrl();
        foreach(var x in y)
        {
            var myItem = ..... create list item;
            tempList.Add(myItem);
        }
        _myListItems.AddRange(tempList);
    }
    
    private ObservableCollectionFast<MyItem> _myListItems = new ObservableCollectionFast<MyItem>();
    

    `

    Where ObservableCollectionFast is:

    `

    public class ObservableCollectionFast<T> : ObservableCollection<T>
     {
        public ObservableCollectionFast() : base() { }
    
        public ObservableCollectionFast(IEnumerable<T> collection) : base(collection) { }
    
        public ObservableCollectionFast(List<T> list) : base(list) { }
    
        public void AddRange(IEnumerable<T> range)
        {
            foreach (var item in range)
            {
                Items.Add(item);
            }
    
            this.OnPropertyChanged(new PropertyChangedEventArgs("Count"));
            this.OnPropertyChanged(new PropertyChangedEventArgs("Item[]"));
            this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
        }
    
        public void Reset(IEnumerable<T> range)
        {
            this.Items.Clear();
    
            AddRange(range);
        }
    }
    

    `

    I can not tell you for sure if this is what has solved my problem.
    Let me know, Byee.

  • IvanMaranIvanMaran USMember ✭✭

    I have this problem too (Xamarin Forms/iOS 2.5.0.12).
    My guess is this is a race condition bug.
    Because, you see, Layout.OnChildMeasureInvalidated() calls both InvalidateMeasureInternal() and Device.BeginInvokeOnMainThread(() =>{
    ...
    layout.SizeAllocated(width, height);
    ...
    }}});

    First call might set _columns=null in the middle of Layout.MeasureGrid() execution right between code checking _columns to be not-null and code accessing _columns.

    For me this looks like a bug in Xamarin.Forms.

  • NickKovalskyNickKovalsky USMember ✭✭✭
    edited September 2018

    It is indeed a bug inside xamarin.forms. This first appeared for me on iOS, today this happened on Android: in MeasuredStarredColumns() _columns.Count was null. https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/GridCalc.cs
    The workaround for me was to force the creation of the first column inserting

    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>
    

    for almost every grid i was using.
    For the xamarin team it would be cool to edit the code adding a null check inside..

  • NickKovalskyNickKovalsky USMember ✭✭✭
    edited September 2018

    All right the above workaround didn't help. Did another thing, this is still going okay, no crashes:
    My theory: when specifying SizeChanged event handler in XAML for a grid it sometimes randomly get called before the grid is initialized = internal crash when trying to build params to pass to event handler.
    Work around: specify the SizeChanged += YourEventHandler in code behind, in constructor, after InitializeComponent line.

  • nathan1658nathan1658 Member ✭✭

    @NickKovalsky said:
    All right the above workaround didn't help. Did another thing, this is still going okay, no crashes:
    My theory: when specifying SizeChanged event handler in XAML for a grid it sometimes randomly get called before the grid is initialized = internal crash when trying to build params to pass to event handler.
    Work around: specify the SizeChanged += YourEventHandler in code behind, in constructor, after InitializeComponent line.

    Im facing the exact issue, can you elaborate more on what you did on the SizeChanged ? Thanks

  • NickKovalskyNickKovalsky USMember ✭✭✭

    @nathan1658 Hey, this crashed happened for me in mainly 2 case ( i guess can be more as they don't check for nulls Columns and Rows inside xamarin code):
    1 when i had a SizeChanged="MyHandler" inside xaml; workaround: delete this in xaml and set same in code behind the SizeChanged+=MyHandler as described in my post above.
    2 when i had a stacklayout inside a grid. this one crashed totally randomly. Sometimes at app start StackLayout tryes to change its size when the parent grid didn't create its columns/rows yet and it crashes. Workaround: obviously avoid this combination as hell.

  • nathan1658nathan1658 Member ✭✭

    Woah thanks for the update! I will look into it, thank you!

    @NickKovalsky said:
    @nathan1658 Hey, this crashed happened for me in mainly 2 case ( i guess can be more as they don't check for nulls Columns and Rows inside xamarin code):
    1 when i had a SizeChanged="MyHandler" inside xaml; workaround: delete this in xaml and set same in code behind the SizeChanged+=MyHandler as described in my post above.
    2 when i had a stacklayout inside a grid. this one crashed totally randomly. Sometimes at app start StackLayout tryes to change its size when the parent grid didn't create its columns/rows yet and it crashes. Workaround: obviously avoid this combination as hell.

  • nathan1658nathan1658 Member ✭✭

    AAAH I tried to simplify the code and still have the issue. No idea what's going on :'(

    I have a simple chat app, with a ListView and CellTemplate

    ^ Just a simple cell template, use a grid to store a label. I Hardcoded AAAAAAAAAAAAAAAAAAAA for the Text.


    ^ Then I move the Label to another ContentView. As you can see it's a very simple one, with just only a label.


    ^ When I run the app then BAM, NullReference at CalculateAutoCells...

    I also found that if I have a short string like "ABC", no exception will be thrown.... so i suspect the issue is somehow related to the calculation of UI?

    Any help would be appreciated, thanks!

  • NickKovalskyNickKovalsky USMember ✭✭✭

    Just that when you have a label inside stacklayout that is inside a grid you randomly get crashes. Yammy. Just avoid it.
    This bug is here for many many xamarin versions. With a sad part that its really easy to fix just check for nulls. And You cannot even make them a reproducible project as its totally random. Depends of how fast was the device, how many resize calculations it did. But then:

    System.NullReferenceException: Object reference not set to an instance of an object.

    11-01 12:23:40.136 I/MonoDroid( 6482): UNHANDLED EXCEPTION:
    11-01 12:23:40.180 I/MonoDroid( 6482): System.NullReferenceException: Object reference not set to an instance of an object.
    11-01 12:23:40.180 I/MonoDroid( 6482): at Xamarin.Forms.Grid.GetAssignedColumnWidth (Xamarin.Forms.BindableObject child) [0x0001c] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:636
    11-01 12:23:40.180 I/MonoDroid( 6482): at Xamarin.Forms.Grid.MeasuredStarredColumns () [0x000af] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:449
    11-01 12:23:40.180 I/MonoDroid( 6482): at Xamarin.Forms.Grid.MeasureAndContractStarredColumns (System.Double width, System.Double height, System.Double totalStarsWidth) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:375
    11-01 12:23:40.180 I/MonoDroid( 6482): at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0010e] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:509
    11-01 12:23:40.180 I/MonoDroid( 6482): at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0002a] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:58
    11-01 12:23:40.180 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:653
    11-01 12:23:40.180 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:535
    11-01 12:23:40.180 I/MonoDroid( 6482): at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:131
    11-01 12:23:40.180 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:593
    11-01 12:23:40.180 I/MonoDroid( 6482): at Xamarin.Forms.Grid.MeasuredStarredColumns () [0x000b9] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:451
    11-01 12:23:40.181 I/MonoDroid( 6482): at Xamarin.Forms.Grid.MeasureAndContractStarredColumns (System.Double width, System.Double height, System.Double totalStarsWidth) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:375
    11-01 12:23:40.181 I/MonoDroid( 6482): at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0010e] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:509
    11-01 12:23:40.181 I/MonoDroid( 6482): at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0002a] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:58
    11-01 12:23:40.181 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:653
    11-01 12:23:40.181 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:535
    11-01 12:23:40.181 I/MonoDroid( 6482): at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:131
    11-01 12:23:40.181 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:593
    11-01 12:23:40.181 I/MonoDroid( 6482): at Xamarin.Forms.StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint) [0x00236] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:198
    11-01 12:23:40.181 I/MonoDroid( 6482): at Xamarin.Forms.StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders) [0x00058] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:123
    11-01 12:23:40.181 I/MonoDroid( 6482): at Xamarin.Forms.StackLayout.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:80
    11-01 12:23:40.181 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:653
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:535
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:131
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) [0x00054] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:593
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.StackLayout.CalculateNaiveLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, Xamarin.Forms.StackOrientation orientation, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint) [0x00236] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:198
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.StackLayout.CalculateLayout (Xamarin.Forms.StackLayout+LayoutInformation layout, System.Double x, System.Double y, System.Double widthConstraint, System.Double heightConstraint, System.Boolean processExpanders) [0x00058] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:123
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.StackLayout.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0005b] in D:\a\1\s\Xamarin.Forms.Core\StackLayout.cs:57
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x0014b] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:263
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:223
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:691
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:920
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:190
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:577
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:177
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.ScrollView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0003d] in D:\a\1\s\Xamarin.Forms.Core\ScrollView.cs:196
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x0014b] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:263
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:223
    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:691
    An unhandled exception occured.

    11-01 12:23:40.182 I/MonoDroid( 6482): at Xamarin.Forms.Layout+<>c.b__45_0 () [0x00080] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:380
    11-01 12:23:40.182 I/MonoDroid( 6482): at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <4d996bab56b14864b2a1299fea73b3fe>:0
    11-01 12:23:40.182 I/MonoDroid( 6482): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <4d996bab56b14864b2a1299fea73b3fe>:0
    11-01 12:23:40.182 I/MonoDroid( 6482): at (wrapper dynamic-method) System.Object.59(intptr,intptr)
    11-01 12:23:40.219 W/zygote ( 6482): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
    11-01 12:23:42.820 E/mono ( 6482):
    11-01 12:23:42.820 E/mono ( 6482): Unhandled Exception:
    11-01 12:23:42.820 E/mono ( 6482): System.NullReferenceException: Object reference not set to an instance of an object.
    11-01 12:23:42.820 E/mono ( 6482): at (wrapper dynamic-method) System.Object.59(intptr,intptr)
    11-01 12:23:42.820 E/mono-rt ( 6482): [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object.

  • NickKovalskyNickKovalsky USMember ✭✭✭
    edited November 2018

    @nathan1658 Fell tired with theses bugs, bye bye Grid: https://stackoverflow.com/a/53104452/7149454

  • JohnHJohnH GBMember ✭✭✭✭✭

    @NickKovalsky said:
    @nathan1658 Fell tired with theses bugs, bye bye Grid: https://stackoverflow.com/a/53104452/7149454

    I haven't seen these issues personally, but if anyone can create an example app that replicates the error, even if doesn't replicate every time but just 1 in 10, I'm sure Xamarin would fix it.

  • shashidharKSshashidharKS USMember ✭✭

    I'm also facing this issue, any one find workaround for it?

  • TomasBergTomasBerg USMember

    Seeing these kind of crashes from our iOS app, Xamarin Forms 2.5.
    What is the status of this? Fixed in XF 3.0 or later?

  • SeanThomas.5523SeanThomas.5523 USMember ✭✭

    This is happening to me too but only in production. I'm seeing it in my crashes in the App Center Diagnostics section. It's never happened a simulator or on one of my test devices.

  • SteeBonoSteeBono ITMember ✭✭
    I solved using FastCells and ObservableCollectionFast.
    Put item inside binding list with AddRange().

    I think that this bug appear when you load too many item in a list inside a Grid and an internal Xamarin method set a variable to null while another method use that variable.

    After those edits to my code, this bug is disappeared.
  • boberbober Member
    edited February 28

    I have the same issue, System.NullReferenceException no stacktrace in Exception Caught Window, in Properties there is a stacktrace, but no info which of my classes are involved. Example Stacktraces:

    Yes I'm using StackLayout in Grids like:
    Page->Grid-> StackLayout-> ListView->ItemTemplate->DataTemplate->ViewCell->CustomComponent
    CustomComponent->Frame->Frame->Grid->Grid/StackLayout ...last Grid contains another Grid with ffimageloading with preview and detail image, fail image and activity indicator

    The Issues happen mostly if the network connection is quite bad, initially if ffimageloading not cached the image.
    Can anyone tell me how i find the custom component that is the reason for the crashes?
    Should i really avoid using StackLayouts in Grid?

    " at Xamarin.Forms.Grid.MeasuredStarredColumns () [0x00179] in amarin.Forms.Core\GridCalc.cs:434
    at Xamarin.Forms.Grid.MeasureAndContractStarredColumns (System.Double width, System.Double height, System.Double totalStarsWidth) [0x00000] in amarin.Forms.Core\GridCalc.cs:375
    ...
    AND (only first Line Mumber is different)

    " at Xamarin.Forms.Grid.MeasuredStarredColumns () [0x00225] in Xamarin.Forms.Core\GridCalc.cs:466
    at Xamarin.Forms.Grid.MeasureAndContractStarredColumns (System.Double width, System.Double height, System.Double totalStarsWidth) [0x00000] in Xamarin.Forms.Core\GridCalc.cs:375

    AND

    " at Xamarin.Forms.Grid.GetUnassignedHeight (System.Double heightRequest) [0x00040] in Xamarin.Forms.Core\GridCalc.cs:675
    at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x000c6] in Xamarin.Forms.Core\GridCalc.cs:129

    AND

    at Xamarin.Forms.Grid.NumberOfUnsetColumnWidth (Xamarin.Forms.BindableObject child) [0x00014] in Xamarin.Forms.Core\\GridCalc.cs:614 
    

    at Xamarin.Forms.Grid.MeasuredStarredColumns () [0x0007b] in Xamarin.Forms.Core\GridCalc.cs:447

    AND

    " at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x001aa] in Xamarin.Forms.Core\GridCalc.cs:109
    at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0000c] in Xamarin.Forms.Core\GridCalc.cs:483

    AND

    " at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x001aa] in amarin.Forms.Core\GridCalc.cs:109
    at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0000c] in amarin.Forms.Core\GridCalc.cs:483

    AND

    " at Xamarin.Forms.Grid.GetAssignedColumnWidth (Xamarin.Forms.BindableObject child) [0x0001c] in Xamarin.Forms.Core\GridCalc.cs:636
    at Xamarin.Forms.Grid.MeasuredStarredColumns () [0x000af] in Xamarin.Forms.Core\GridCalc.cs:449

    AND

    " at Xamarin.Forms.Grid.GetLastAutoRow (Xamarin.Forms.BindableObject child) [0x00016] in Xamarin.Forms.Core\GridCalc.cs:667
    at Xamarin.Forms.Grid.ExpandLastAutoRowIfNeeded (System.Double height, System.Boolean expandToRequest) [0x00024] in Xamarin.Forms.Core\GridCalc.cs:356

    AND if I test more, I'll probably find more. :-(

  • JohnWostenbergJohnWostenberg USMember ✭✭

    I'm experiencing this too. Though I'm getting reports that it's also happening on Android (don't have a stacktrace handy for that platform at the moment though). I'm going to work on submitting a proper Github issue; this is completely debilitating. It crashes most times you navigate to the problem page.

    `System.NullReferenceException: Object reference not set to an instance of an object
    at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x00195] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:113
    at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0000c] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:485
    at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0000e] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:18
    at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
    at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
    at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
    at Xamarin.Forms.Layout+<>c.b__45_0 () [0x00080] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:381
    at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/Foundation/NSAction.cs:152
    --- End of stack trace from previous location where exception was thrown ---

    at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
    at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIApplication.cs:79
    at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIApplication.cs:63
    at RedactedApp.iOS.Application.Main (System.String[] args) [0x00001] in /Users/jwostenberg/Code/RedactedApp/src/RedactedApp/RedactedApp.iOS/Main.cs:17`

  • JohnWostenbergJohnWostenberg USMember ✭✭

    I'm experiencing this too. Though I'm getting reports that it's also happening on Android (don't have a stacktrace handy for that platform at the moment though). I'm going to work on submitting a proper Github issue; this is completely debilitating. It crashes most times you navigate to the problem page.

    `System.NullReferenceException: Object reference not set to an instance of an object
    at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x00195] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:113
    at Xamarin.Forms.Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) [0x0000c] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:485
    at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0000e] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:18
    at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
    at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
    at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
    at Xamarin.Forms.Layout+<>c.b__45_0 () [0x00080] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:381
    at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/Foundation/NSAction.cs:152
    --- End of stack trace from previous location where exception was thrown ---

    at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
    at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIApplication.cs:79
    at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.2/src/Xamarin.iOS/UIKit/UIApplication.cs:63
    at RedactedApp.iOS.Application.Main (System.String[] args) [0x00001] in /Users/jwostenberg/Code/RedactedApp/src/RedactedApp/RedactedApp.iOS/Main.cs:17`

  • KalyanKalyan Member

    I am also facing same issue in android in Xamarin forms

    StackTrace
    Grid.CalculateAutoCells (System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:113
    Grid.MeasureGrid (System.Double width, System.Double height, System.Boolean requestSize) D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:485
    Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:60
    VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:762
    VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:644
    Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) D:\a\1\s\Xamarin.Forms.Core\Layout.cs:132
    VisualElement.Measure (System.Double widthConstraint, System.Double heightConstraint, Xamarin.Forms.MeasureFlags flags) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:702
    ScrollView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\ScrollView.cs:230
    Layout.UpdateChildrenLayout () D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
    Layout.OnSizeAllocated (System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
    VisualElement.SizeAllocated (System.Double width, System.Double height) D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
    Layout+<>c.b__45_0 () D:\a\1\s\Xamarin.Forms.Core\Layout.cs:381
    Thread+RunnableImplementor.Run ()
    IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this)
    (wrapper dynamic-method) System.Object.26(intptr,intptr)

Sign In or Register to comment.