Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[regression/8.0.0-rc1] [Android] Removing ItemSource item in ListView causes crash #17028

Closed
drasticactions opened this issue Aug 28, 2023 · 1 comment · Fixed by #17084
Closed
Labels
area-controls-listview ListView and TableView fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 high It doesn't work at all, crashes or has a big impact. i/regression This issue described a confirmed regression on a currently supported version platform/android 🤖 t/bug Something isn't working
Milestone

Comments

@drasticactions
Copy link
Contributor

Description

If you have a dynamic ItemSource on a ListView, and remove any item other than the last item in the given source, your application will crash on an error The specified child already has a parent. You must call removeView() on the child's parent first..

  • The ListView Caching must be set to "RetainElement", the others work.
  • This only happens on Android
  • This only seems to happen in Main, not the current Releaes versions of MAUI (as of 7.0.92 or net8.0)

Steps to Reproduce

Checkout my repro project and run it against MAUI Main.

  1. Click on Add Item to add an item
  2. Click Remove Item, it should remove the item
  3. Click Add Item two times
  4. Click Remove Item once

In the current (7.0.92, .NET 8 Preview) builds it should work, but in Main it should fail.

Link to public reproduction project repository

https://github.com/drasticactions/MauiRepros/tree/main/ListViewMaui7

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

7.0.92

Affected platforms

Android

Affected platform versions

Android

Did you find any workaround?

Don't remove the first item in an ItemSource on a listview.

Relevant log output

**Java.Lang.IllegalStateException:** 'The specified child already has a parent. You must call removeView() on the child's parent first.'
 	0x11 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw	C#
 	0x89 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:12324,5	C#
 	0x78 in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeVirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:75,7	C#
 	0x38 in Android.Views.ViewGroup.AddView at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:1999,5	C#
>	0x2B in Microsoft.Maui.Controls.Handlers.Compatibility.ViewCellRenderer.ViewCellContainer.AddView at C:\Users\timill\source\repos\maui\src\Controls\src\Core\Compatibility\Handlers\ListView\Android\ViewCellRenderer.cs:279,6	C#
 	0x26D in Microsoft.Maui.Controls.Handlers.Compatibility.ViewCellRenderer.ViewCellContainer.Update at C:\Users\timill\source\repos\maui\src\Controls\src\Core\Compatibility\Handlers\ListView\Android\ViewCellRenderer.cs:247,5	C#
 	0x33 in Microsoft.Maui.Controls.Handlers.Compatibility.ViewCellRenderer.GetCellCore at C:\Users\timill\source\repos\maui\src\Controls\src\Core\Compatibility\Handlers\ListView\Android\ViewCellRenderer.cs:25,5	C#
 	0xFE in Microsoft.Maui.Controls.Handlers.Compatibility.CellRenderer.GetCell at C:\Users\timill\source\repos\maui\src\Controls\src\Core\Compatibility\Handlers\ListView\Android\CellRenderer.cs:72,4	C#
 	0x4A in Microsoft.Maui.Controls.Handlers.Compatibility.CellFactory.GetCell at C:\Users\timill\source\repos\maui\src\Controls\src\Core\Compatibility\Handlers\ListView\Android\CellFactory.cs:27,4	C#
 	0x31A in Microsoft.Maui.Controls.Handlers.Compatibility.ListViewAdapter.GetView at C:\Users\timill\source\repos\maui\src\Controls\src\Core\Compatibility\Handlers\ListView\Android\ListViewAdapter.cs:332,4	C#
 	0x1C in Android.Widget.BaseAdapter.n_GetView_ILandroid_view_View_Landroid_view_ViewGroup_ at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Widget.BaseAdapter.cs:538,4	C#
 	0x23 in Android.Runtime.DynamicMethodNameCounter.6	C#
 	0x39 in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a	C#
 	0x74 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:12320,4	C#
 	0x2D in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:93,6	C#
 	0x69 in Android.Views.ViewGroup.Layout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3369,5	C#
 	0x2B in Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<Microsoft.Maui.Controls.ListView>.OnLayout at C:\Users\timill\source\repos\maui\src\Controls\src\Core\Compatibility\Handlers\Android\VisualElementRenderer.cs:53,6	C#
 	0x9 in Microsoft.Maui.Controls.Handlers.Compatibility.ListViewRenderer.OnLayout at C:\Users\timill\source\repos\maui\src\Controls\src\Core\Compatibility\Handlers\ListView\Android\ListViewRenderer.cs:303,4	C#
 	0x10 in Android.Views.ViewGroup.n_OnLayout_ZIIII at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3655,4	C#
 	0x11 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:429,5	C#
 	0x39 in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a	C#
 	0x74 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:12320,4	C#
 	0x2D in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:93,6	C#
 	0x69 in Android.Views.ViewGroup.Layout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3369,5	C#
 	0xFE in Microsoft.Maui.ViewHandlerExtensions.PlatformArrangeHandler at C:\Users\timill\source\repos\maui\src\Core\src\Handlers\ViewHandlerExtensions.Android.cs:133,4	C#
 	0x2 in Microsoft.Maui.Controls.Handlers.Compatibility.VisualElementRenderer<Microsoft.Maui.Controls.ListView>.Microsoft.Maui.IViewHandler.PlatformArrange at C:\Users\timill\source\repos\maui\src\Controls\src\Core\Compatibility\Handlers\VisualElementRenderer.cs:231,4	C#
 	0x21 in Microsoft.Maui.Controls.VisualElement.ArrangeOverride at C:\Users\timill\source\repos\maui\src\Controls\src\Core\VisualElement\VisualElement.cs:1816,4	C#
 	0x3 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Arrange at C:\Users\timill\source\repos\maui\src\Controls\src\Core\VisualElement\VisualElement.cs:1804,4	C#
 	0x81 in Microsoft.Maui.Layouts.GridLayoutManager.ArrangeChildren at C:\Users\timill\source\repos\maui\src\Core\src\Layouts\GridLayoutManager.cs:46,5	C#
 	0x8 in Microsoft.Maui.Controls.Layout.CrossPlatformArrange at C:\Users\timill\source\repos\maui\src\Controls\src\Core\Layout\Layout.cs:261,4	C#
 	0x13 in Microsoft.Maui.Platform.LayoutViewGroup.CrossPlatformArrange at C:\Users\timill\source\repos\maui\src\Core\src\Platform\Android\LayoutViewGroup.cs:62,4	C#
 	0x36 in Microsoft.Maui.Platform.LayoutViewGroup.OnLayout at C:\Users\timill\source\repos\maui\src\Core\src\Platform\Android\LayoutViewGroup.cs:111,4	C#
 	0x10 in Android.Views.ViewGroup.n_OnLayout_ZIIII at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3655,4	C#
 	0x11 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:429,5	C#
 	0x39 in Java.Interop.NativeMethods.java_interop_jnienv_call_nonvirtual_void_method_a	C#
 	0x74 in Java.Interop.JniEnvironment.InstanceMethods.CallNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/obj/Release/net7.0/JniEnvironment.g.cs:12320,4	C#
 	0x2D in Java.Interop.JniPeerMembers.JniInstanceMethods.InvokeNonvirtualVoidMethod at /Users/runner/work/1/s/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop/JniPeerMembers.JniInstanceMethods_Invoke.cs:93,6	C#
 	0x69 in Android.Views.ViewGroup.Layout at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3369,5	C#
 	0xFE in Microsoft.Maui.ViewHandlerExtensions.PlatformArrangeHandler at C:\Users\timill\source\repos\maui\src\Core\src\Handlers\ViewHandlerExtensions.Android.cs:133,4	C#
 	0x2 in Microsoft.Maui.Handlers.ViewHandler<Microsoft.Maui.ILayout,Microsoft.Maui.Platform.LayoutViewGroup>.PlatformArrange at C:\Users\timill\source\repos\maui\src\Core\src\Handlers\View\ViewHandlerOfT.Android.cs:15,4	C#
 	0x21 in Microsoft.Maui.Controls.VisualElement.ArrangeOverride at C:\Users\timill\source\repos\maui\src\Controls\src\Core\VisualElement\VisualElement.cs:1816,4	C#
 	0x3 in Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IView.Arrange at C:\Users\timill\source\repos\maui\src\Controls\src\Core\VisualElement\VisualElement.cs:1804,4	C#
 	0x62 in Microsoft.Maui.Layouts.LayoutExtensions.ArrangeContent at C:\Users\timill\source\repos\maui\src\Core\src\Layouts\LayoutExtensions.cs:182,4	C#
 	0xB in Microsoft.Maui.Controls.ContentPage.Microsoft.Maui.ICrossPlatformLayout.CrossPlatformArrange at C:\Users\timill\source\repos\maui\src\Controls\src\Core\ContentPage\ContentPage.cs:93,4	C#
 	0x13 in Microsoft.Maui.Platform.ContentViewGroup.CrossPlatformArrange at C:\Users\timill\source\repos\maui\src\Core\src\Platform\Android\ContentViewGroup.cs:56,4	C#
 	0x2B in Microsoft.Maui.Platform.ContentViewGroup.OnLayout at C:\Users\timill\source\repos\maui\src\Core\src\Platform\Android\ContentViewGroup.cs:99,4	C#
 	0x10 in Android.Views.ViewGroup.n_OnLayout_ZIIII at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Android.Views.ViewGroup.cs:3655,4	C#
 	0x11 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPZIIII_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:429,5	C#


[ft.maui.sandbox] java_vm_ext.cc:594] (Throwable with no stack trace)
[ft.maui.sandbox] java_vm_ext.cc:594] 
[ft.maui.sandbox] java_vm_ext.cc:594]     in call to CallObjectMethodA
[ft.maui.sandbox] java_vm_ext.cc:594]     from android.view.View crc64e1fb321c08285b90.ListViewAdapter.n_getView(int, android.view.View, android.view.ViewGroup)
**Java.Lang.IllegalStateException:** 'Loading...'
@drasticactions drasticactions added the t/bug Something isn't working label Aug 28, 2023
@rmarinho rmarinho added this to the Backlog milestone Aug 28, 2023
@ghost
Copy link

ghost commented Aug 28, 2023

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.

@rmarinho rmarinho added the i/regression This issue described a confirmed regression on a currently supported version label Aug 28, 2023
@rmarinho rmarinho modified the milestones: Backlog, .NET 8 GA Aug 28, 2023
@samhouts samhouts changed the title [Android/Main] Removing ItemSource item in ListView causes crash [regression/8.0.0-rc1] [Android] Removing ItemSource item in ListView causes crash Aug 28, 2023
@samhouts samhouts added the high It doesn't work at all, crashes or has a big impact. label Aug 28, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 29, 2023
@samhouts samhouts added the fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 label Jan 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-listview ListView and TableView fixed-in-8.0.0-rc.1.9171 Look for this fix in 8.0.0-rc.1.9171 high It doesn't work at all, crashes or has a big impact. i/regression This issue described a confirmed regression on a currently supported version platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants