xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] Crash on XF4.8.0.1821 and XF5.0.0.1931 "NaN is not a valid value for width at Xamarin.Forms.Size..ctor" #13735

Open alexeystrakh opened 3 years ago

alexeystrakh commented 3 years ago

Description

An application crashes after upgrade from XF4.7.1351 to XF4.8.0.1821 (and also crashes on the latest stable XF5.0.0.1931) with the following error:

2021-02-10 14:11:38.110016-0800 MyApp.Ios[44648:17427944] Unhandled managed exception: NaN is not a valid value for width (System.ArgumentException)
  at Xamarin.Forms.Size..ctor (System.Double width, System.Double height) [0x00008] in D:\a\1\s\Xamarin.Forms.Core\Size.cs:20 
  at Xamarin.Forms.Grid+GridStructure.ComputeCurrentSize (System.Double columnSpacing, System.Double rowSpacing) [0x0000d] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:290 
  at Xamarin.Forms.Grid+GridStructure.ContractStarRowsIfNeeded (System.Double targetHeight, System.Double columnSpacing, System.Double rowSpacing) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:426 
  at Xamarin.Forms.Grid+GridStructure.MeasureAndContractStarredRows (Xamarin.Forms.Grid grid, System.Double width, System.Double height, System.Double totalStarsHeight) [0x000dd] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:640 
  at Xamarin.Forms.Grid+GridStructure..ctor (Xamarin.Forms.Grid grid, System.Double width, System.Double height, System.Boolean requestSize) [0x000f8] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:137 
  at Xamarin.Forms.Grid.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x0002a] in D:\a\1\s\Xamarin.Forms.Core\GridCalc.cs:55 
  at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:796 
  at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in D:\a\1\s\Xamarin.Forms.Core\VisualElement.cs:686 

Steps to Reproduce

  1. Upgrade the XF package for the existing application from XF4.7.1351 to XF4.8.0.1821 (or up to XF5.0.0.1931)
  2. Run the app - crash

Expected Behavior

The application doesn't crash after the XF upgrade

Actual Behavior

The application crashes with the exception above

Basic Information

Environment

Show/Hide Visual Studio info ``` === Visual Studio Enterprise 2019 for Mac === Version 8.8.8 (build 12) Installation UUID: 197b4b8d-2a9a-4fbd-896c-cd74849affd3 GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638) Package version: 612000113 === Mono Framework MDK === Runtime: Mono 6.12.0.113 (2020-02/4fdfb5b1fd5) (64-bit) Package version: 612000113 === Roslyn (Language Service) === 3.8.0-5.20519.18+4c195c3ac1974edcefa76774d7a59a2350ec55fa === NuGet === Version: 5.8.0.6860 === .NET Core SDK === SDK: /usr/local/share/dotnet/sdk/5.0.103/Sdks SDK Versions: 5.0.103 5.0.102 5.0.101 5.0.100 5.0.100-rc.2.20479.15 3.1.406 3.1.405 3.1.404 3.1.403 3.1.402 3.1.401 3.1.302 3.1.301 3.1.300 3.1.201 3.1.200 3.1.102 3.1.100 3.1.100-preview3-014645 3.1.100-preview2-014569 3.0.100 2.1.701 2.1.700 2.1.505 2.1.504 2.1.500 2.1.402 2.1.302 2.1.301 2.1.4 MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks === .NET Core Runtime === Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 5.0.3 5.0.2 5.0.1 5.0.0 5.0.0-rc.2.20475.5 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.0 3.1.0-preview3.19553.2 3.1.0-preview2.19525.6 3.0.0 2.1.23 2.1.22 2.1.21 2.1.20 2.1.19 2.1.18 2.1.17 2.1.16 2.1.15 2.1.14 2.1.13 2.1.12 2.1.11 2.1.9 2.1.8 2.1.6 2.1.4 2.1.2 2.1.1 2.0.5 === .NET Core 3.1 SDK === SDK: 3.1.406 === Xamarin.Profiler === Version: 1.6.12.31 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler === Updater === Version: 11 === Apple Developer Tools === Xcode 12.4 (17801) Build 12D4e === Xamarin.Mac === Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/usr/bin/mmp. === Xamarin.iOS === Version: 14.10.0.4 (Visual Studio Enterprise) Hash: 5a05865f6 Branch: xcode12.4 Build date: 2021-01-28 02:30:23-0500 === Xamarin Designer === Version: 16.8.0.510 Hash: 44e3f3ce9 Branch: remotes/origin/d16-8 Build date: 2020-12-10 00:06:14 UTC === Xamarin.Android === Version: 11.1.0.26 (Visual Studio Enterprise) Commit: xamarin-android/d16-8/a36ce73 Android SDK: /Users/astrakh/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 5.0 (API level 21) 5.1 (API level 22) 6.0 (API level 23) 7.1 (API level 25) 8.0 (API level 26) 8.1 (API level 27) SDK Tools Version: 26.1.1 SDK Platform Tools Version: 29.0.4 SDK Build Tools Version: 29.0.2 Build Information: Mono: 5e9cb6d Java.Interop: xamarin/java.interop/d16-8@79d9533 ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000 SQLite: xamarin/sqlite/3.32.1@1a3276b Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc === Microsoft OpenJDK for Mobile === Java SDK: /Users/astrakh/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25 1.8.0-25 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL === Android SDK Manager === Version: 16.8.0.32 Hash: 01a7774 Branch: remotes/origin/d16-8 Build date: 2021-01-14 00:34:58 UTC === Android Device Manager === Version: 16.8.0.46 Hash: 0a81419 Branch: remotes/origin/d16-8 Build date: 2021-01-14 00:35:22 UTC === Build Information === Release ID: 808080012 Git revision: 147eee6fcc43c486d8b79477b6a521322a015604 Build date: 2021-02-04 04:32:34-05 Build branch: release-8.8 Xamarin extensions: 147eee6fcc43c486d8b79477b6a521322a015604 === Operating System === Mac OS X 10.16.0 Darwin 20.2.0 Darwin Kernel Version 20.2.0 Wed Dec 2 20:39:59 PST 2020 root:xnu-7195.60.75~1/RELEASE_X86_64 x86_64 === Enabled user installed extensions === XAML Styler 2.0.1 Xamarin Hot Reload 20190830.17 ```

Crash Logs

iOS: grid-size-nan-is-not-a-valid-value.txt

Android: grid-size-nan-is-not-a-valid-value-android.txt

Workaround

No workaround found, this is a blocking XF upgrade issue.

SeRgI1982 commented 3 years ago

I have also experienced this bug :/

Basic Information Version with issue: XF 5.0.0.1931 Platform Target Frameworks: macOS: 10.13.6 (High Sierra) Affected Devices: MacBook Pro (2.53 GHz Intel Core 2 Duo, 8 GB, NVIDIA GeForce 9400M 256 MB, Mid 2009)

write_nocancel(0x2, "[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: NaN is not a valid value for height at Xamarin.Forms.Size..ctor (System.Double width, System.Double height) [0x0001b] in <82bf00d73ba84d498079d53808841321>:0 at Xamarin.Forms.VisualElement.G", 0x400) = 1024 0 write_nocancel(0x2, "traint, System.Double heightConstraint) [0x0002a] in <82bf00d73ba84d498079d53808841321>:0 at Xamarin.Forms.VisualElement.OnMeasure (System.Double widthConstraint, System.Double heightConstraint) [0x00000] in <82bf00d73ba84d498079d53808841321>:0 at Xa", 0x400) = 1024 0 write_nocancel(0x2, "t) [0x00000] in <82bf00d73ba84d498079d53808841321>:0 at Xamarin.Forms.VisualElement.GetSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00053] in <82bf00d73ba84d498079d53808841321>:0 \n at Xamarin.Forms.Layout.GetSizeReques", 0x400) = 1024 0 write_nocancel(0x2, "arin.Forms.Layout.OnSizeAllocated (System.Double width, System.Double height) [0x0000f] in <82bf00d73ba84d498079d53808841321>:0 at Xamarin.Forms.VisualElement.SizeAllocated (System.Double width, System.Double height) [0x00000] in <82bf00d73ba84d498079d5", 0x400) = 1024 0 write_nocancel(0x2, "X.Controls.Menu.SampleGrid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x00011] in /Users/MyUser/SampleX/Sample.Products.SampleX/Controls/Menu/SampleGrid.cs:21 at Xamarin.Forms.Layout.UpdateChildrenLayout () [0x", 0x400) = 1024 0 write_nocancel(0x2, "n (Xamarin.Forms.VisualElement child, Xamarin.Forms.Rectangle region) [0x001da] in <82bf00d73ba84d498079d53808841321>:0 at Xamarin.Forms.Grid.LayoutChildren (System.Double x, System.Double y, System.Double width, System.Double height) [0x0015e] in <82bf", 0x400) = 1024 0 write_nocancel(0x2, "21>:0 \n at Xamarin.Forms.VisualElement.set_Bounds (Xamarin.Forms.Rectangle value) [0x0006c] in <82bf00d73ba84d498079d53808841321>:0 at Xamarin.Forms.VisualElement.Layout (Xamarin.Forms.Rectangle bounds) [0x00000] in <82bf00d73ba84d498079d53808841321>:0", 0x400) = 1024 0 write_nocancel(0x2, "a84d498079d53808841321>:0 at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Interna", 0x400) = 1024 0 write_nocancel(0x2, "s.VisualElement.set_IsVisible (System.Boolean value) [0x00000] in <82bf00d73ba84d498079d53808841321>:0 at Sample.Products.SampleX.Views.MapPage.<ShowContextMenu>b__137_0 () [0x00020] in /Users/MyUser/SampleX/Sample.Products.SampleX/Views/MapPage.xaml.cs:1038

About XAML - nothing special: AbsoluteLayout as a main container, ContextMenu which is a ContentView with Grid and a few base XF controls like BoxView, Labels, Buttons etc.

The exception was thrown also in another case where I had different simple custom control also inside AbsoluteLayout. this another custom control was even hidden (IsVisible = false) and the app crashed when I tried navigate to that ContentPage.

Those controls were not touched during last few months and everything worked properly with previous version (XF 4.8.0.1821)

Interesting thing: it works properly on MacBooks with version:

SeRgI1982 commented 3 years ago

By the way, can you tell me how you test the app on old macOS version (for ex. High Sierra) ? We try to be up to date with Xamarin Forms, Visual Studio for mac and XCode (if needed). Installing an old version of VS for mac and XCode on this machine with High Sierra is not helpful because most of the Xamarin packages + Mono requires higher version. In VS for mac there is no option for remote debugging

SeRgI1982 commented 3 years ago

I think that I have found the problem. Problematic is Line control. Take a look on sample - with Lines the app crash on Hight Sierra. When you replace them by BoxView control - everything works good.

SizeIssueSample.zip

alexeystrakh commented 3 years ago

We were able to detect the control which is crashing the app after the XF upgrade. It's a BoxView with an improperly calculated width request. The BoxView control is part of a bigger hierarchy of a 3d party control.

var width = ... // infinity
this.boxView.WidthRequest = width