CarouselView change programmatically Position property or CurrentItem Property throw Java.Lang.IllegalStateException: 'The specified child already has a parent. You must call removeView() on the child's parent first.' #22504
Labels
area-controls-collectionview
CollectionView, CarouselView, IndicatorView
migration-compatibility
Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert
platform/android 🤖
s/triaged
Issue has been reviewed
s/verified
Verified / Reproducible Issue ready for Engineering Triage
t/bug
Something isn't working
Milestone
Description
On android platform, when programmatically switching between items in a CarouselView, a Java.Lang.IllegalStateException is thrown: 'The specified child already has a parent. You must call removeView() on the child's parent first.' The bug is floating, it can be reproduced from the code of the attached repository. You need to switch between tabs many times (20 or more) until the error appears. I made a recording of an android emulator.
Steps to Reproduce
Expected: application works stably
Actual: application crashes
maui-andrioid.mp4
Link to public reproduction project repository
https://github.com/kbezzubov/TabViewControl
Version with bug
8.0.40 SR5
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms, Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 14
Did you find any workaround?
I have a workaround:
In the log I see the following lines:
From which it follows that the ContentViewHandler and the UpdateContent method need to be corrected.
To do this, you can write a custom handler for ContentView, in which the UpdateContent method will look like this:
In my repository, there is an implementation of this handler. To make sure that this works, you need to uncomment the line in the MauiProgram.cs file where the handler is registered:
Relevant log output
The text was updated successfully, but these errors were encountered: