Hi,
I'm using a custom FrameRenderer in my UWP project to style frames (corner radius and color). When I scroll a bit back and forth, the app crashes with a System.ArgumentException: Value does not fall within the expected range. It's the call to base.OnElementChanged(e);
that causes it.
I can of course put that in a try/catch, but then some items in my list will disappear. They return on orientation change of the device, but not after a normal refresh of the FlowListView I'm using.
Any ideas? I'm on Xamarin Forms 2.5.1.444934.
Here's the custom FrameRenderer:
class ExtendedFrameRenderer : FrameRenderer { protected override void OnElementChanged(ElementChangedEventArgs<Frame> e) { base.OnElementChanged(e); if (Control != null) { var frame = e.NewElement; double cornerRadius = frame.CornerRadius; Windows.UI.Color frameBG = Windows.UI.Color.FromArgb( (byte)(frame.BackgroundColor.A * 255), (byte)(frame.BackgroundColor.R * 255), (byte)(frame.BackgroundColor.G * 255), (byte)(frame.BackgroundColor.B * 255)); Control.CornerRadius = new Windows.UI.Xaml.CornerRadius(cornerRadius); Control.Background = new SolidColorBrush(frameBG); frame.BackgroundColor = Xamarin.Forms.Color.Transparent; } } }
Full error stack:
System.ArgumentException HResult=0x80070057 Message=Value does not fall within the expected range. Source=Windows StackTrace: at Windows.UI.Xaml.Controls.Border.put_Child(UIElement value) at Xamarin.Forms.Platform.UWP.FrameRenderer.PackChild() at Xamarin.Forms.Platform.UWP.FrameRenderer.OnElementChanged(ElementChangedEventArgs`1 e) at MyApp.UWP.Helpers.ExtendedFrameRenderer.OnElementChanged(ElementChangedEventArgs`1 e) in C:\Users\me\Source\Workspaces\MySol\MyApp\MyApp.UWP\Helpers\ExtendedFrameRenderer.cs:line 26 at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element) at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element) at Xamarin.Forms.Platform.UWP.VisualElementPackager.OnChildAdded(Object sender, ElementEventArgs e) at Xamarin.Forms.Platform.UWP.VisualElementPackager.Load() at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element) at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element) at Xamarin.Forms.Platform.UWP.VisualElementPackager.OnChildAdded(Object sender, ElementEventArgs e) at Xamarin.Forms.Platform.UWP.VisualElementPackager.Load() at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement(VisualElement element) at Xamarin.Forms.Platform.UWP.Platform.CreateRenderer(VisualElement element) at Xamarin.Forms.Platform.UWP.ViewToRendererConverter.WrapperControl..ctor(View view) at Xamarin.Forms.Platform.UWP.ViewToRendererConverter.Convert(Object value, Type targetType, Object parameter, String language)
Answers
Same problem with 2.5.1.527436 (latest supported by VisualStudio 2015). Maybe you should report the bug.
To work around the problem, you can implement a renderer that doesn't derive from the FrameRenderer but ViewRenderer instead, which is what the FrameRenderer derives from - see Xamarin.Forms.Platform.UAP/FrameRenderer.cs in the Xamarin.Forms repo (I'd post a link if I could)
The advantage is that stuff will be correctly typed given a custom TElement (first type argument to the ViewRenderer)
Confirmed for 2.5.1.527436. Maybe report the bug
As a workaround, you could derive directly from the, using Xamarin.Forms/Xamarin.Forms.Platform.UAP/FrameRenderer.cs as a reference.
Same problem with 2.5.1.527436 (latest supported by VisualStudio 2015). Maybe you should report the bug.
To work around the problem, you can implement a renderer that doesn't derive from the FrameRenderer but ViewRenderer instead, which is what the FrameRenderer derives from - see Xamarin.Forms.Platform.UAP/FrameRenderer.cs in the Xamarin.Forms repo (I'd post a link if I could)
The advantage is that stuff will be correctly typed given a custom TElement (first type argument to the ViewRenderer)
Confirmed for 2.5.1.527436. Maybe report the bug
As a workaround, you could derive directly from the, using Xamarin.Forms/Xamarin.Forms.Platform.UAP/FrameRenderer.cs as a reference.
Sorry for multiple posts, I was just now approved for posting after being a registered user for over a year.
Any updates on this? I'm facing the same issue on Xamarin.Forms 3.0.0.482510.
As long as I use a custom renderer, that issues occurs. But it crashes in the base.OnElementChanged(e); method, as JThun pointed out.
Hi @DevEloper.8993, and thank you for trying to help!
Do you have any ideas on how to work around the issue by deriving from ViewRenderer? As it crashes on
Control.Child = renderer.ContainerElement;
in FrameRenderer, I'm out of ideas.@JThun - I also use a custom renderer derived from FrameRenderer on UWP. I'm not seeing the problem that you are getting, either on 2.4.x or 2.5.x (I don't plan on moving to 3.0 until I absolutely have to). I'm not using FlowListView though. Do you see the same problem when not using FlowListView?
Have you logged a bug with a repro sample?
I've been trying to reproduce in a clean project, but no luck. Seems that it might be a timing issue in my prod app related to the UI complexity with ad controls etc.
Would you have an example code in which the error happens? I would like to understand the reason better because I have tried to reproduce the problem and I can not.
@JThun did you or anyone ever report this bug to Xamarin.Forms via github?
github.com/xamarin/Xamarin.Forms/issues
I'm getting a crash in FrameRenderer at the same spot, but I'm not using a custom renderer.
What's stopping upgraded from 2.5.x to 3.4 (unless your unfortunate enough to still have to support Windows Mobile)? we deprecated Windows mobile phone with the last 2.5.x release of the app and then moved to 3.x & .NETStandard, it affected 4 users....
If this crash is occurring in 3.4.0 it's serious an should should be raised as an issue.
Yep, this issue exists in XF3.4.0.1029999
Hello All,
Any update on this issue or any workaround possible. I am facing the same issue in XF version 4.5.0.617.