Xamarin.forms: Value does not fall with in the expected range Exception while creating NativeView Xamarin Forms UWP

Created on 11 Apr 2019  路  8Comments  路  Source: xamarin/Xamarin.Forms

Description

Hi Team,

We at Syncfusion develop data visualization controls for Xamarin, Please refer the below link for a description about us.
UserGuide: https://help.syncfusion.com/xamarin/sfdatagrid/overview
FeatureTour: https://www.syncfusion.com/products/xamarin.

This is to bring to your notice, a possible bug in the Xamarin.Forms.UWP renderer creation.

In the attached (SimpleSample.zip), i have a simple scroll view, with a grid layout as its content. In the聽button click(Create Renderer) i pass聽the scrollview and the control flow to the UWP renderer using a DependencyService, where, i use the Platform.CreateRenderer() to create a native renderer first.

Then in the next button click(Start native view conversion), i again pass the scrollview and the flow to the UWP renderer using a DependencyService where i first check, whether the given forms view ( scroll view) has a native renderer using the code.
Platform.GetRenderer(scrollview)

Then if a renderer exists, i dispose the renderer and set null value to the renderer property of the scroll view. Refer the below code.

var renderer = Platform.GetRenderer(formsView);
聽聽聽聽聽聽聽聽聽聽聽聽if (renderer != null)
聽聽聽聽聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽renderer.Dispose();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽Platform.SetRenderer(formsView, null);
聽聽聽聽聽聽聽聽聽聽聽聽}
Now i again create a new native renderer for the same forms view ( scroll view) . At this point i get the below exception.

image

To investigate further and to get more details of the crash i cloned the ScrollViewRenderer.cs of UWP from the below link聽https://github.com/xamarin/Xamarin.Forms/blob/bd31e1e9fc8b2f9ad94cc99e0c7ab058174821f3/Xamarin.Forms.Platform.UAP/VisualElementExtensions.cs
and registered this custom renderer for ScrollView and was able to zero down the root cause,聽

In the UpdateContent method of the UWP ScrollViewRenderer, in line number 145, you are trying to set content to the native UWP's scroll view. Here renderer.ContainerElement is of type page renderer. May be this could be the issue.聽
image
Upon adding try catch for the same, was able to get the below error as exception message.
The parameter is incorrect. SliderStyle.xaml is not a valid absolute URI

You could find this CustomRenderer in the name of MyScrollViewRenderer in the UWP project. Ensure to un comment the renderer registration line above the namespace to trigger my custom renderer.

In the other attached sample, we would have installed the SfPopupLayout nugets, where the actual issue was reproduced. You can have a look at that too for reference.

Steps to Reproduce

  1. Run the Sample named as SimpleSample
  2. Click the button Create native renderer
  3. Then Click the Start native view conversion
  4. Exception has occurred as mentioned above

Expected Behavior

CustomRenderer(ScrollViewRenderer) should be converted to native view with out any exception

Actual Behavior

While converting CustomRenderer(ScrollViewRenderer) getting exception

Basic Information

  • Version with issue: 3.6
  • Last known good version:
  • IDE:
  • Platform Target Frameworks:

    • UWP:

  • Nuget Packages:
  • Affected Devices:

Reproduction Link

SimpleSample => http://www.syncfusion.com/downloads/support/directtrac/general/ze/SimpleSample-891056696
SfPopupLayoutSample => http://www.syncfusion.com/downloads/support/directtrac/general/ze/SfPopupLayoutSample-1292317045

1 high UWP partner bug

Most helpful comment

@nschoenberg this work around might help you. I wrote a helper that just on UWP removes any of the templates, then shows the popup and then adds the templates back. Works well, just note, if you try that on iOS or Android it won't work, so make sure to only open the popup without templates on UWP
`
private static void InternalSafeShow(SfPopupLayout popup, Action showAction)
{
switch (Xamarin.Forms.Device.RuntimePlatform)
{
case Xamarin.Forms.Device.UWP:
var contentTemplate = popup.PopupView.ContentTemplate;
var headerTemplate = popup.PopupView.HeaderTemplate;

    popup.PopupView.HeaderTemplate = null;
    popup.PopupView.ContentTemplate = null;
    showAction(popup);
    popup.PopupView.HeaderTemplate = headerTemplate;
    popup.PopupView.ContentTemplate = contentTemplate;
        return;

    default:
           showAction(popup);
        return;
    }
}

`

All 8 comments

+1

+1 Also, I might be biased though because I'm pretty sure this is related to a bug I filed with SyncFusion :)

I also have this issue and this prevents my team from upgrading XF 3.4 to 3.6 together with newest syncfusion version.

@nschoenberg this work around might help you. I wrote a helper that just on UWP removes any of the templates, then shows the popup and then adds the templates back. Works well, just note, if you try that on iOS or Android it won't work, so make sure to only open the popup without templates on UWP
`
private static void InternalSafeShow(SfPopupLayout popup, Action showAction)
{
switch (Xamarin.Forms.Device.RuntimePlatform)
{
case Xamarin.Forms.Device.UWP:
var contentTemplate = popup.PopupView.ContentTemplate;
var headerTemplate = popup.PopupView.HeaderTemplate;

    popup.PopupView.HeaderTemplate = null;
    popup.PopupView.ContentTemplate = null;
    showAction(popup);
    popup.PopupView.HeaderTemplate = headerTemplate;
    popup.PopupView.ContentTemplate = contentTemplate;
        return;

    default:
           showAction(popup);
        return;
    }
}

`

Hi @samhouts, Any update on this?

Hi @samhouts

Can you please let us know whether this issue has fixed in last stable Forms version 4.1.0.555618 or not? If not let us know when this fix will be included ?

@DeepikaBalaSubramaniyan It is not yet merged. I expect it will be merged this week and released in a service release shortly thereafter. Thank you for your patience.

closed by #6557

Was this page helpful?
0 / 5 - 0 ratings