Skip to content

Using CollectionView.EmptyView results in an Exception on Windows #28212

@omghb

Description

@omghb

Description

We get an Exception from CollectionView.EmptyView after migrating from MAUI 8.0.93 to MAUI 9.0.40.

If we add items to the CollectionView and then navigate a second time to this page we get the exception Element is already the child of another element on Windows. This results in a crash of the App.

Development note: The Page using the CollectionView is a singleton.

Steps to Reproduce

  1. Clone and run repro solution from GitHub repo: https://github.com/omghb/MauiIssue28212
  2. Perform the same steps than shown in the video:
    Image
  3. If you change the MAUI version to 8.0.93 then this issue will no occur.

Link to public reproduction project repository

No response

Version with bug

9.0.40 SR4

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.93 SR9.3

Affected platforms

  • Windows
  • Not affected platforms: The same navigation works fine on Android and iOS.

Affected platform versions

Win 10 22H2

Did you find any workaround?

protected override void OnAppearing()
{
    base.OnAppearing();
    collectionView.EmptyView = new CustomEmptyView();
}

protected override void OnDisappearing()
{
    collectionView.EmptyView = null;
    base.OnDisappearing();
}

Relevant log output

Microsoft.UI.Xaml.UnhandledExceptionEventArgs

No installed components were detected.

Element is already the child of another element.


at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32 hr)
   at ABI.Microsoft.UI.Xaml.Controls.IContentControlMethods.set_Content(IObjectReference _obj, Object value)
   at Microsoft.UI.Xaml.Controls.ContentControl.set_Content(Object value)
   at Microsoft.Maui.Controls.Platform.FormsListView.OnApplyTemplate()
   at Microsoft.UI.Xaml.FrameworkElement.Microsoft.UI.Xaml.IFrameworkElementOverrides.OnApplyTemplate()
   at ABI.Microsoft.UI.Xaml.IFrameworkElementOverrides.Do_Abi_OnApplyTemplate_2(IntPtr thisPtr)
--- End of stack trace from previous location ---
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32 hr)
   at ABI.Microsoft.UI.Xaml.IUIElementMethods.Measure(IObjectReference _obj, Size availableSize)
   at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize)
   at Microsoft.Maui.ViewHandlerExtensions.GetDesiredSizeFromHandler(IViewHandler viewHandler, Double widthConstraint, Double heightConstraint)
   at Microsoft.Maui.Handlers.ViewHandler`2.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.GridLayoutManager.GridStructure.MeasureCell(Cell cell, Double width, Double height)
   at Microsoft.Maui.Layouts.GridLayoutManager.GridStructure.SecondMeasurePass()
   at Microsoft.Maui.Layouts.GridLayoutManager.GridStructure.MeasureCells()
   at Microsoft.Maui.Layouts.GridLayoutManager.GridStructure..ctor(IGridLayout grid, Double widthConstraint, Double heightConstraint)
   at Microsoft.Maui.Layouts.GridLayoutManager.Measure(Double widthConstraint, Double heightConstraint)
   at Microsoft.Maui.Controls.Layout.CrossPlatformMeasure(Double widthConstraint, Double heightConstraint)
   at Microsoft.Maui.Platform.MauiPanel.CrossPlatformMeasure(Double widthConstraint, Double heightConstraint)
   at Microsoft.Maui.Platform.MauiPanel.MeasureOverride(Size availableSize)
   at Microsoft.UI.Xaml.FrameworkElement.Microsoft.UI.Xaml.IFrameworkElementOverrides.MeasureOverride(Size availableSize)
   at ABI.Microsoft.UI.Xaml.IFrameworkElementOverrides.Do_Abi_MeasureOverride_0(IntPtr thisPtr, Size availableSize, Size* result)
--- End of stack trace from previous location ---
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|38_0(Int32 hr)
   at ABI.Microsoft.UI.Xaml.IUIElementMethods.Measure(IObjectReference _obj, Size availableSize)
   at Microsoft.UI.Xaml.UIElement.Measure(Size availableSize)
   at Microsoft.Maui.ViewHandlerExtensions.GetDesiredSizeFromHandler(IViewHandler viewHandler, Double widthConstraint, Double heightConstraint)
   at Microsoft.Maui.Handlers.ViewHandler`2.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.MauiPanel.CrossPlatformMeasure(Double widthConstraint, Double heightConstraint)
   at Microsoft.Maui.Platform.MauiPanel.MeasureOverride(Size availableSize)
   at Microsoft.UI.Xaml.FrameworkElement.Microsoft.UI.Xaml.IFrameworkElementOverrides.MeasureOverride(Size availableSize)
   at ABI.Microsoft.UI.Xaml.IFrameworkElementOverrides.Do_Abi_MeasureOverride_0(IntPtr thisPtr, Size availableSize, Size* result)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-collectionviewCollectionView, CarouselView, IndicatorViewi/regressionThis issue described a confirmed regression on a currently supported versionpartner/syncfusionIssues / PR's with Syncfusion collaborationregressed-in-9.0.0s/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions