-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug] NullReference Exception: Grid.MeasureGrid (Android) #6247
Comments
@InquisitorJax Can you please attach a small project that demonstrates this issue? Thanks! |
Hi @samhouts ... bit snowed under with work, can't make any promises. Perhaps try adding a Grid to NavigationPage.TitleView with some content. That's the only "out of the ordinary" thing I see there. |
I've found the offending grid - nested within a ContentView Grid... but's it's 1 a.m here - so I'm calling it a night. If whomever picks up this ticket needs to look at the code over skype - feel free to contact 'inquisitorjax' |
I get a similar error after upgrading to version 4. Seems that it happens when I hide the grid. System.NullReferenceException: Object reference not set to an instance of an object.
|
@kwaclaw sounds about right. My landing page has a few grids / content views where the visibility is bound to ViewModel State. |
@kwaclaw Same problem here. @InquisitorJax did you find any resolution? |
@softsan not yet - unfortunately I have other priorities atm. |
I can confirm the problem as well. Seems to be a race condition after setting/updating the bindingcontext, because it does not occour every time. Exception
Xaml <?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="...">
<ContentView.Resources>
<ResourceDictionary Source="/Theming/CustomerDisplay.xaml" />
<Style TargetType="Label">
<Setter Property="FontFamily"
Value="{StaticResource MonoFontThin}" />
<Setter Property="TextColor"
Value="Black" />
<Setter Property="FontSize"
Value="Large" />
</Style>
</ContentView.Resources>
<Grid Margin="20,10,20,10"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="7*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="60" />
</Grid.RowDefinitions>
<CollectionView ItemsSource="{Binding Path=Items}"
VerticalOptions="EndAndExpand"
HorizontalOptions="FillAndExpand"
SelectionMode="None"
Grid.ColumnSpan="2">
<CollectionView.ItemTemplate>
<!-- many content... -->
</CollectionView.ItemTemplate>
</CollectionView>
<Label Text="Total"
FontAttributes="Bold"
VerticalOptions="CenterAndExpand"
HorizontalOptions="FillAndExpand"
Grid.Row="1" />
<Label Text="{Binding Total}"
FontAttributes="Bold"
FontSize="42"
VerticalOptions="CenterAndExpand"
HorizontalOptions="EndAndExpand"
Grid.Row="1"
Grid.Column="1" />
</Grid>
</ContentView> Code behind namespace My.Name.Space
{
public partial class CustomerDisplayBookingView : ContentView
{
public CustomerDisplayBookingView(int width, int height, object bindingContext)
{
InitializeComponent();
WidthRequest = width;
HeightRequest = height;
BindingContext = bindingContext;
}
}
} Instanciation on looper thread var view = new CustomerDisplayBookingView(854, 480, bookingLayout); Further information |
I'm getting the same crash each time when navigating back from an oauth browser session. Special note |
When I look at the number of bugs posted in the last 48 hours it seems wise to revert back to version 3.6. |
Can anyone having this issue test with the nuget attached here? let me know if it still happens Another fix that might work is to roll back to legacy renderers |
Perfect, It works. |
I stumbled upon this same issue when upgrading to 4 from 3.6, and going back to legacy renderers according to your suggestion solved my crashes! |
In my case the problem was a not fully layouted forms view. There is a complex viewmodel with many bindings behind. Adding a delay solved my issue! async static Task<ViewGroup> ConvertToNativeAsync(Xamarin.Forms.View view, Android.Content.Context context, bool ignoreDensity)
{
var renderer = Platform.CreateRendererWithContext(view, context);
if (renderer == null)
return null;
renderer.Tracker.UpdateLayout();
var density = context.Resources.DisplayMetrics.Density;
var nativeDensityModifier = ignoreDensity ? 1 : density;
var formsDensityModifier = ignoreDensity ? density : 1;
var nativeSize = new Xamarin.Forms.Rectangle(0, 0, view.WidthRequest * nativeDensityModifier, view.HeightRequest * nativeDensityModifier);
var formsSize = new Xamarin.Forms.Rectangle(0, 0, view.WidthRequest / formsDensityModifier, view.HeightRequest / formsDensityModifier);
var viewGroup = renderer.View as ViewGroup;
viewGroup.LayoutParameters = new ViewGroup.LayoutParams((int)nativeSize.Width, (int)nativeSize.Height);
view.Layout(formsSize);
// Solves the problem!
await Task.Delay(TimeSpan.FromMilliseconds(600));
viewGroup.Layout(0, 0, (int)nativeSize.Width, (int)nativeSize.Height);
return viewGroup;
} |
I have this bug :( System.NullReferenceException: Object reference not set to an instance of an object |
We also got an AppCenter crash report with this issue for iPhone 6s (iOS 13.3). This issue is imho not related to a specific platform, but rather to Xamarin.Forms in general. |
I now got the confirmation that this bug is definitely a cross platform issue, as it also happened on an iPhone XR running iOS 13.3.1. The stacktrace: https://pastebin.com/hfaHXN2x |
Same exception here. It only occurs on a page where the visibility of a grid is bound to a viewmodel property. I can not reproduce it, I only see a lot of appcenter traces for iPhones. Have not seen this on Android.
|
Any updates on this one? Update:
It can be reproduced with this code if you have few rows/columns defined
|
Hi Any updates on this issue? Thank you! |
Description
the intention of this this code here
Xamarin.Forms/Xamarin.Forms.Core/GridCalc.cs
Line 19 in bd31e1e
Needs to be propagated through the rest of the grid control
The issue here
#6274
raised the probability of that type of situation arising.
The same treatment was already given to StackLayout but it should probably also be reconciled against the other layouts to see if there are similar scenarios where wayward invalidate measures can cause null exceptions
Related issue fixed for SL
#4689
Description Original
null reference exception when upgrading to xamarin forms 4 (android)
Steps to Reproduce
Expected Behavior
Don't crash
Actual Behavior
Crashes like a bomb :(
Basic Information
Screenshots
Reproduction Link
Stack Trace
UNHANDLED EXCEPTION:
05-21 22:38:23.984 I/MonoDroid( 6859): System.NullReferenceException: Object reference not set to an instance of an object.
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x00357] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:146
05-21 22:38:23.984 I/MonoDroid( 6859): 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
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0002a] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:60
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:762
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:644
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:132
05-21 22:38:23.984 I/MonoDroid( 6859): 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:702
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x00110] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:166
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00144] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:49
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1023
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:307
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:686
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:178
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.TemplatedView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:27
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1023
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:307
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:686
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:178
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00144] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:49
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
05-21 22:38:23.984 I/MonoDroid( 6859): at Xamarin.Forms.Layout+<>c.b__45_0 () [0x00080] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:381
05-21 22:38:23.984 I/MonoDroid( 6859): at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <95d915721ad748108ff096dce8f8f32c>:0
05-21 22:38:23.984 I/MonoDroid( 6859): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <95d915721ad748108ff096dce8f8f32c>:0
05-21 22:38:23.984 I/MonoDroid( 6859): at (wrapper dynamic-method) System.Object.40(intptr,intptr)
05-21 22:38:24.012 E/Crash Report( 6859): Time: 5/21/2019 10:38:23 PM
05-21 22:38:24.012 E/Crash Report( 6859): Error: Unhandled Exception
05-21 22:38:24.012 E/Crash Report( 6859): System.Exception: Android_UnhandledExceptionRaiser ---> System.NullReferenceException: Object reference not set to an instance of an object.
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Grid.CalculateAutoCells (System.Double width, System.Double height) [0x00357] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:146
05-21 22:38:24.012 E/Crash Report( 6859): 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
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0002a] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:60
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:762
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:644
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:132
05-21 22:38:24.012 E/Crash Report( 6859): 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:702
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x00110] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:166
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00144] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:49
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1023
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0005d] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:307
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:686
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:178
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.TemplatedView.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\TemplatedView.cs:27
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x00158] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:266
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in D:\a\1\s\Xamarin.Forms.Core\Layout.cs:224
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:784
05-21 22:38:24.012 E/Crash Report( 6859): at Xamarin.Forms.VisualElement.SetSize (System.Double width, System.Double height) [0x00021] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:1023
[5:GlobalExceptionManagerBase.LogUnhandledException] 1|2019-05-21 22:38:24.0168|FATAL|Time: 5/21/2019 10:38:23 PM
The text was updated successfully, but these errors were encountered: