maui icon indicating copy to clipboard operation
maui copied to clipboard

[regression/8.0.0-preview.1.7762] [WinUI] An exception is thrown after removing an item from its close button

Open marchev-prgs opened this issue 1 year ago • 13 comments

Description

I get the exception with 8.0.0-preview.6.8686, which I don't see listed in the versions list below)

An exception is thrown when an item is removed by clicking a close-button inside the item. I have a simple item template, just a label and a close-button:

    <DataTemplate x:Key="t1">
        <HorizontalStackLayout>
            <Label Text="{Binding}" Margin="0, 0, 10, 0" />
            <Button Text="X" Clicked="ButtonClose_Clicked" />
        </HorizontalStackLayout>
    </DataTemplate>

When I click the close button an exception is thrown: Message: Child collection must not be modified during measure or arrange.

Interestingly, the stack trace is null.

cv_exc2_app

cv_exc2_exc ee-455020fde0ca)

Steps to Reproduce

  1. Get the repo from the link
  2. Go to folder \Maui\CollectionViewThrowsExceptionWhenClosingAnItem
  3. Run the app in WinUI
  4. Click the X button (the close button of the item in the CollectionVew)

Expected: The item should be removed and the CollectionView should become empty. Actual: An exception is thrown.

Link to public reproduction project repository

https://github.com/telerik/ms-samples/tree/main/Maui/CollectionViewThrowsExceptionWhenClosingAnItem

Version with bug

8.0.0-preview.1.7762

Last version that worked well

7.0.92

Affected platforms

Windows

Affected platform versions

Did you find any workaround?

https://github.com/dotnet/maui/issues/16324#issuecomment-1758406716

Relevant log output

No response

Depends on

  • [x] https://github.com/microsoft/microsoft-ui-xaml/issues/6350

VS bug #1900743

marchev-prgs avatar Jul 24 '23 16:07 marchev-prgs

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

ghost avatar Jul 31 '23 14:07 ghost

Verified this on Visual Studio Enterprise 17.8.0 Preview 1.0. This issue does not repro on Windows 11(8.0.100-preview.6.23330.14), Android 13.0-API33 and iOS 16.4 with below Project:

CollectionViewThrowsExc2.zip

NoException

XamlTest avatar Aug 10 '23 08:08 XamlTest

Hi @marchev-prgs. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Aug 10 '23 08:08 ghost

Interestingly, I still get an exception - "Child collection must not be modified during measure or arrange." Unfortunately, the exception is the "No installed components were detected." exception, so I cannot give you stack trace as well. I am running VS 17.8.0 Preview 1.0 and maui is 8.0.0-preview.7.8842.

marchev-prgs avatar Aug 11 '23 15:08 marchev-prgs

I figured I can give you what I see in the Call Stack window of VS. I doubt it's of much use, but I guess it wouldn't hurt:

CollectionViewThrowsExc2.dll!CollectionViewThrowsExc2.WinUI.App.InitializeComponent.AnonymousMethod__3_1(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) Line 67 C# Microsoft.WinUI.dll!WinRT._EventSource_global__Microsoft_UI_Xaml_UnhandledExceptionEventHandler.EventState.GetEventInvoke.AnonymousMethod__1_0(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) Unknown Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.UnhandledExceptionEventHandler.Do_Abi_Invoke(nint thisPtr, nint sender, nint e) Unknown [Native to Managed Transition] [Managed to Native Transition] Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.Controls.IItemsControlOverridesMethods.OnItemsChanged(WinRT.IObjectReference _obj, object e) Unknown Microsoft.WinUI.dll!Microsoft.UI.Xaml.Controls.ItemsControl.OnItemsChanged(object e) Unknown Microsoft.WinUI.dll!Microsoft.UI.Xaml.Controls.ItemsControl.Microsoft.UI.Xaml.Controls.IItemsControlOverrides.OnItemsChanged(object e) Unknown Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.Controls.IItemsControlOverrides.Do_Abi_OnItemsChanged_4(nint thisPtr, nint e) Unknown [Native to Managed Transition] [Managed to Native Transition] WinRT.Runtime.dll!ABI.System.Collections.Specialized.NotifyCollectionChangedEventHandler.NativeDelegateWrapper.Invoke(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) Unknown System.ObjectModel.dll!System.Collections.ObjectModel.ObservableCollection<Microsoft.Maui.Controls.Platform.ItemTemplateContext>.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) Unknown Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Platform.ObservableItemTemplateCollection.Remove(System.Collections.Specialized.NotifyCollectionChangedEventArgs args) Unknown Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Platform.ObservableItemTemplateCollection.InnerCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs args) Unknown Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Platform.ObservableItemTemplateCollection.InnerCollectionChanged.AnonymousMethod__0() Unknown Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.DispatcherExtensions.DispatchIfRequired(Microsoft.Maui.Dispatching.IDispatcher dispatcher, System.Action action) Unknown Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Platform.ObservableItemTemplateCollection.InnerCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs args) Unknown System.ObjectModel.dll!System.Collections.ObjectModel.ObservableCollection.OnCollectionChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) Unknown System.Private.CoreLib.dll!System.Collections.ObjectModel.Collection.Remove(string item) Unknown CollectionViewThrowsExc2.dll!CollectionViewThrowsExc2.MainPage.ButtonClose_Clicked(object sender, System.EventArgs e) Line 21 C# Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Button.Microsoft.Maui.Controls.Internals.IButtonElement.PropagateUpClicked() Unknown Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.ButtonElement.ElementClicked(Microsoft.Maui.Controls.VisualElement visualElement, Microsoft.Maui.Controls.Internals.IButtonElement ButtonElementManager) Unknown Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Button.SendClicked() Unknown Microsoft.Maui.Controls.dll!Microsoft.Maui.Controls.Button.Microsoft.Maui.IButton.Clicked() Unknown Microsoft.Maui.dll!Microsoft.Maui.Handlers.ButtonHandler.OnClick(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) Unknown Microsoft.WinUI.dll!WinRT._EventSource_global__Microsoft_UI_Xaml_RoutedEventHandler.EventState.GetEventInvoke.AnonymousMethod__1_0(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) Unknown Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke(nint thisPtr, nint sender, nint e) Unknown [Native to Managed Transition] [Managed to Native Transition] Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.Controls.IControlOverridesMethods.OnPointerReleased(WinRT.IObjectReference _obj, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) Unknown Microsoft.WinUI.dll!Microsoft.UI.Xaml.Controls.Control.OnPointerReleased(Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) Unknown Microsoft.WinUI.dll!Microsoft.UI.Xaml.Controls.Control.Microsoft.UI.Xaml.Controls.IControlOverrides.OnPointerReleased(Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e) Unknown Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.Controls.IControlOverrides.Do_Abi_OnPointerReleased_3(nint thisPtr, nint e) Unknown [Native to Managed Transition] [Managed to Native Transition] Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.IApplicationStaticsMethods.Start(WinRT.IObjectReference _obj, Microsoft.UI.Xaml.ApplicationInitializationCallback callback) Unknown Microsoft.WinUI.dll!Microsoft.UI.Xaml.Application.Start(Microsoft.UI.Xaml.ApplicationInitializationCallback callback) Unknown CollectionViewThrowsExc2.dll!CollectionViewThrowsExc2.WinUI.Program.Main(string[] args) Line 31 C#

marchev-prgs avatar Aug 11 '23 15:08 marchev-prgs

The root cause of the bug looks directly related to WinUI core issues with observable collections and collection views (ListView in this case). Bret already linked an existing and related bug in WinUI. I'll try to file a new one specific to this issue and attach a repro solution.

mauroa avatar Sep 06 '23 19:09 mauroa

Confirmed that this regressed between https://github.com/dotnet/maui/compare/7.0.92...8.0.0-preview.1.7762. https://github.com/dotnet/maui/pull/10999 and https://github.com/dotnet/maui/pull/13146 seem sus, but it could be one of the memory leaks fixes on bindings, too, perhaps?

samhouts avatar Sep 08 '23 00:09 samhouts

Cannot reproduce the issue with Windows 10: issue-16324 Probably related with latests WinUI versions, will check with Windows 11.

jsuarezruiz avatar Sep 18 '23 07:09 jsuarezruiz

Unfortunatly this is an issue on WinUI related to https://github.com/microsoft/microsoft-ui-xaml/issues/6350.

We are working with the WinUI team to get this fixed, and as a workaround you can release the button's pointer capture before removing the item from the list.

For example, the sample code linked on this issue would look like:

private void ButtonClose_Clicked(object sender, EventArgs e)
{
	Button button = (Button)sender;

#if WINDOWS
	((Microsoft.UI.Xaml.Controls.Button)button.Handler.PlatformView).ReleasePointerCaptures();
#endif

	string item = (string)button.BindingContext;
	this.items.Remove(item);
}

emaf avatar Oct 11 '23 19:10 emaf

I'm going to backlog this issue for now. We're going to wait for this to be resolved by WinUI

PureWeen avatar Nov 03 '23 21:11 PureWeen

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

ghost avatar Nov 03 '23 21:11 ghost

https://github.com/microsoft/microsoft-ui-xaml/issues/8684

busitech avatar Apr 17 '24 22:04 busitech

Hi @marchev-prgs. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.

You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.