Xamarin Forms UWP System.ArgumentException RRS feed

  • Question

  • User395103 posted

    Hi, I'm working on Xamarin Forms project with custom map renderers on all three platforms. I'm using bindable properties to pass data to the renderers. It works fine on IoS and Android but not on UWP. I've done a significant amount of debugging. The UWP exceptions have no line numbers, at least in this case. I'm getting a System.ArgumentException -- value does not fall within the expected range. The one time I was able to get Visual Studio debugger to throw a meaningful stacktrace pointing to code in the project, I got this:

    at Windows.UI.Xaml.UIElement.Measure(Size availableSize) at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.GetDesiredSize(Double widthConstraint, Double heightConstraint) at Xamarin.Forms.Platform.UWP.Platform.GetNativeSize(VisualElement element, Double widthConstraint, Double heightConstraint) at Xamarin.Forms.VisualElement.OnSizeRequest(Double widthConstraint, Double heightConstraint) at Xamarin.Forms.VisualElement.GetSizeRequest(Double widthConstraint, Double heightConstraint) at Xamarin.Forms.VisualElement.Measure(Double widthConstraint, Double heightConstraint, MeasureFlags flags) at Xamarin.Forms.StackLayout.CalculateNaiveLayout(LayoutInformation layout, StackOrientation orientation, Double x, Double y, Double widthConstraint, Double heightConstraint) at Xamarin.Forms.StackLayout.CalculateLayout(LayoutInformation layout, Double x, Double y, Double widthConstraint, Double heightConstraint, Boolean processExpanders) at Xamarin.Forms.StackLayout.LayoutChildren(Double x, Double y, Double width, Double height) at Xamarin.Forms.Layout.UpdateChildrenLayout() at Xamarin.Forms.VisualElement.SetSize(Double width, Double height) at Xamarin.Forms.VisualElement.setBounds(Rectangle value) at Xamarin.Forms.Layout.LayoutChildIntoBoundingRegion(VisualElement child, Rectangle region) at Xamarin.Forms.AbsoluteLayout.LayoutChildren(Double x, Double y, Double width, Double height) at Xamarin.Forms.Layout.UpdateChildrenLayout() at Xamarin.Forms.Element.OnPropertyChanged(String propertyName) at Xamarin.Forms.BindableObject.SetValueActual(BindableProperty property, BindablePropertyContext context, Object value, Boolean currentlyApplying, SetValueFlags attributes, Boolean silent) at Xamarin.Forms.BindableObject.SetValueCore(BindableProperty property, Object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes) at Xamarin.Forms.BindingExpression.ApplyCore(Object sourceObject, BindableObject target, BindableProperty property, Boolean fromTarget) at Xamarin.Forms.BindingExpression.Apply(Boolean fromTarget) at Xamarin.Forms.BindingExpression.BindingExpressionPart.PropertyChanged(Object sender, PropertyChangedEventArgs args) at Xamarin.Forms.BindingExpression.WeakPropertyChangedProxy.OnPropertyChanged(Object sender, PropertyChangedEventArgs e) at JCX.ViewModels.CleanMapViewModel.setMapBounds(Rectangle value) in C:\Users\or39\Documents\JCX\JCX\JCX\ViewModels\CleanMapViewModel.cs:line 746 at JCX.ViewModels.CleanMapViewModel.b_3620() in C:\Users\or39\Documents\JCX\JCX\JCX\ViewModels\CleanMapViewModel.cs:line 1177

    I commented out anything related to the MapBounds but the exception continued. It always hits the auto-generated App.g.cs file with an unhandled exception. I've tried different map keys, removing large sections of code, debug assertions, and debug log statements. It seems to be something with external code. A post that is related to this issue is the following: https://forums.xamarin.com/discussion/125971/system-argumentexception-crash-in-custom-uwp-framerenderer Is this a UWP Xamarin bug or a compatibility issue?

    Tuesday, June 9, 2020 5:37 PM


  • User395103 posted

    After narrowing it down through a lot of debugging (commenting out Xaml to isolate the issue), I found the solution. The Telerik Buttons have an issue when running on UWP. Windows had "changed the behavior of UWP controls and default values for null when it's a non nullable property type. Traditionally, you'd use "-1", but that's no longer accepted and causes an OutofRangeException, Therefore, by overriding the default -1 with 0, you avoid the exception" (feedback.telerik.com/xamarin/1402384-button-uwp-argumentexception-is-raised-when-targeting-windows-10-version-1809). You must put "BorderThickness = 0" for the Telerik Buttons on UWP; it also shows up on RadBorder as well. So it turned out to be a compatibility issue, as I thought, with a workaround.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, June 10, 2020 4:03 PM