MAUI .NET 8 on iOS -System.ArgumentException: NaN is not a valid value for width
I have created a new MAUI .NET 8 project and migrated the Xamarin forms project code. When tried to run the project with the iOS simulator with Jetbrains Rider, which threw the exception below,
System.ArgumentException: NaN is not a valid value for width
at Microsoft.Maui.Graphics.Size..ctor(Double width, Double height)
at Microsoft.Maui.ViewHandlerExtensions.GetDesiredSizeFromHandler(IViewHandler viewHandler, Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.IView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[UIKit.UIView, Microsoft.iOS, Version=17.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].GetDesiredSize(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Layouts.LayoutExtensions.ComputeDesiredSize(IView view, Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Controls.VisualElement.MeasureOverride(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Measure(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Layouts.VerticalStackLayoutManager.Measure(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Controls.StackLayoutManager.Measure(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Controls.Layout.CrossPlatformMeasure(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Platform.MauiView.CrossPlatformMeasure(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Platform.MauiView.SizeThatFits(CGSize size)
at Microsoft.Maui.ViewHandlerExtensions.GetDesiredSizeFromHandler(IViewHandler viewHandler, Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Handlers.ViewHandler`2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].GetDesiredSize(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Layouts.LayoutExtensions.ComputeDesiredSize(IView view, Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Controls.VisualElement.MeasureOverride(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Measure(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Layouts.LayoutExtensions.MeasureContent(IContentView contentView, Thickness inset, Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Layouts.LayoutExtensions.MeasureContent(IContentView contentView, Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Controls.ContentPage.Microsoft.Maui.ICrossPlatformLayout.CrossPlatformMeasure(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Platform.MauiView.CrossPlatformMeasure(Double widthConstraint, Double heightConstraint)
at Microsoft.Maui.Platform.MauiView.LayoutSubviews()
at Microsoft.Maui.Platform.ContentView.LayoutSubviews()
at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 58
at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 94
at SKM_MOBILE.Program.Main(String[] args) in /Users/macmini3/Documents/MAUI/SKM_MOBILE/SKM_MOBILE/Platforms/iOS/Program.cs:line 13
--------------------------------------------------------------------------------------------------------------------------------
In my Xamarin project, I used the CustomRender, I just wanted to use the same code in the converted MAUI project, so I added the below code in the MauiProgram.cs file as per this https://learn.microsoft.com/en-gb/dotnet/maui/migration/custom-renderers?view=net-maui-8.0 documentation,
handlers.AddCompatibilityRenderer(typeof(CustomButton), typeof(SKM_MOBILE.iOS.Renderers.ButtonRenderer_IOS));
Did I miss anything? How do I resolve this issue?
Please sign in to leave a comment.
Per my investigation it should not be related to your IDE settings, have a check if the same code works on older iOS versions.
I noticed some similar problem was reported in Xamarin.Forms repo.