Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] The specified child already has a parent #13399

Open
MarcoSal opened this issue Jan 14, 2021 · 4 comments
Open

[Bug] The specified child already has a parent #13399

MarcoSal opened this issue Jan 14, 2021 · 4 comments
Assignees
Labels
a/swipeview e/3 🕒 3 in-progress This issue has an associated pull request that may resolve it! p/Android t/bug 🐛

Comments

@MarcoSal
Copy link

Description

I have an error that only showed up today. until yesterday it worked fine. in the meantime i have updated visual studio.
xamarin forms is 5.0
the error reports:
Java.Lang.IllegalStateException: 'The specified child already has a parent. You must call removeView () on the child's parent first. '

(https://forums.xamarin.com/discussion/comment/428174#Comment_428174)

I have a scrollview which contains a variety of information (like whatsapp).

Steps to Reproduce

  1. public ObservableCollection <FlowNote> FlowNoteList {get {return Get <ObservableCollection <FlowNote>> (); } set {Set (value); OnPropertyChanged (); }}
  2. FlowNote fn = FlowNoteList.SingleOrDefault (Predicate => Predicate.IdNota == idnote); FlowNoteList.Remove (fn);
  3.              <StackLayout x:Name="FlowStackLayout" VerticalOptions="Start">
                     <ListView x:Name="FlowListView" ItemsSource="{Binding FlowNoteList}" IsVisible="True" HasUnevenRows="True" SeparatorVisibility="Default">
                         <ListView.ItemTemplate>
                             <DataTemplate>
                                 <ViewCell>
                                     <SwipeView x:Name="swipView" SwipeStarted="SwipeView_SwipeStarted" SwipeEnded="SwipeView_SwipeEnded">
                                         <SwipeView.LeftItems>
                                             <SwipeItems>
                                                 <SwipeItem Text="Share"
                                                    BackgroundColor="#2196F3"
                                                    Invoked="OnShareSwipeItemInvoked" >
                                                     <SwipeItem.IconImageSource>
                                                         <FontImageSource Color="Black" Size="15" FontFamily="UserIcons" Glyph="{Static models:FontIconsClass.Share}"></FontImageSource>
                                                     </SwipeItem.IconImageSource>
                                                 </SwipeItem>
                                                 <SwipeItem Text="Edit" IsVisible="{Binding isMe, Converter={StaticResource isMeBoolInvertConverter}}"
                                                    BackgroundColor="#2196F3"
                                                            Invoked="OnEditNoteSwipeItemInvoked" >
                                                     <SwipeItem.IconImageSource>
                                                         <FontImageSource Color="Black" Size="15" FontFamily="UserIcons" Glyph="{Static models:FontIconsClass.CommentEdit}"></FontImageSource>
                                                     </SwipeItem.IconImageSource>
                                                 </SwipeItem>
                                             </SwipeItems>
                                         </SwipeView.LeftItems>
                                         <SwipeView.RightItems>
                                             <SwipeItems>
                                                 <SwipeItem Text="Delete" IsVisible="{Binding isMe, Converter={StaticResource isMeBoolInvertConverter}}"
                                                    BackgroundColor="#2196F3"
                                                    Command="{Binding Path=BindingContext.UserDeleteNotaCommand, Source={x:Reference FlowStackLayout}}" CommandParameter="{Binding IdNota}" >
                                                     <SwipeItem.IconImageSource>
                                                         <FontImageSource Color="Red" Size="15" FontFamily="UserIcons" Glyph="{Static models:FontIconsClass.Delete}"></FontImageSource>
                                                     </SwipeItem.IconImageSource>
                                                 </SwipeItem>
                                             </SwipeItems>
                                         </SwipeView.RightItems>
    
                                         <Grid>
                                             <Grid.ColumnDefinitions>
                                                 <ColumnDefinition Width="40"/>
                                                 <ColumnDefinition Width="*"/>
                                                 <ColumnDefinition Width="40"/>
                                             </Grid.ColumnDefinitions>
    
                                             <Frame Style="{Binding isMe, Converter={StaticResource IntToFrameChatBackgroundConverter}}" Grid.Column="{Binding isMe}" Margin="5" Grid.ColumnSpan="2" >
                                                 <StackLayout Style="{Binding isMe, Converter={StaticResource IntToFrameChatBackgroundConverter}}" Grid.Column="{Binding isMe}" Margin="5" Grid.ColumnSpan="2" >
                                                     <Grid>
                                                         <Grid.ColumnDefinitions>
                                                             <ColumnDefinition/>
                                                             <ColumnDefinition/>
                                                             <ColumnDefinition Width="20"/>
                                                         </Grid.ColumnDefinitions>
                                                         <Label Text="{Binding User.Username}" TextColor="Black" IsVisible="{Binding isMe, Converter={StaticResource isMeBoolConverter}}" Margin="2" FontSize="12" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand"/>
                                                         <Label Text="{Binding Data, StringFormat=' {0:dd-MMM-yy HH:mm}'}" Grid.Column="1" TextColor="Black" Margin="2" FontSize="12" HorizontalOptions="EndAndExpand" VerticalOptions="StartAndExpand"/>
                                                         <Image Grid.Column="2" HorizontalOptions="Center">
                                                             <Image.GestureRecognizers>
                                                                 <TapGestureRecognizer Tapped="RowMenu_tapped" CommandParameter="{Binding PathDoc}" NumberOfTapsRequired="1"></TapGestureRecognizer>
                                                             </Image.GestureRecognizers>
                                                             <Image.Source>
                                                                 <FontImageSource Color="Black" Size="25" FontFamily="UserIcons" Glyph="{Static models:FontIconsClass.DotsVertical}"></FontImageSource>
                                                             </Image.Source>
                                                         </Image>
                                                     </Grid>
                                                     <Label Text="{Binding Titolo}" TextColor="Black" IsVisible="{Binding Titolo, Converter={StaticResource StringNullOrEmptyBoolConverter}}" Margin="2" FontAttributes="Bold" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand">
                                                         <Label.GestureRecognizers>
                                                             <TapGestureRecognizer Tapped="OnTitoloTapped" NumberOfTapsRequired="2"/>
                                                         </Label.GestureRecognizers>
                                                     </Label>
                                                     <Label Text="{Binding Nota}" LineBreakMode="WordWrap" TextColor="Black" IsVisible="{Binding Nota, Converter={StaticResource StringNullOrEmptyBoolConverter}}" Margin="2" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand">
                                                         <Label.GestureRecognizers>
                                                             <TapGestureRecognizer Tapped="OnEditNoteTapped" NumberOfTapsRequired="2"/>
                                                         </Label.GestureRecognizers>
                                                     </Label>
                                                     <Image IsVisible="{Binding AllegatoList, Converter={StaticResource ObservableCollectionMultipleBoolConverter}}" HorizontalOptions="Start">
                                                         <Image.Source>
                                                             <FontImageSource Color="Black" Size="25" FontFamily="UserIcons" Glyph="{Static models:FontIconsClass.Attachment}"></FontImageSource>
                                                         </Image.Source>
                                                     </Image>
                                                     <StackLayout x:Name="BindableLayoutAllegati" BindableLayout.ItemsSource="{Binding AllegatoList}">
                                                         <!--https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/layouts/bindable-layouts-->
                                                         <BindableLayout.ItemTemplate>
                                                             <DataTemplate>
                                                                 <StackLayout HorizontalOptions="CenterAndExpand">
                                                                     <Grid IsVisible="{Binding PathDoc, Converter={StaticResource IsAudioValueConverter}}" HeightRequest="60">
                                                                         <Grid.ColumnDefinitions>
                                                                             <ColumnDefinition Width="60"/>
                                                                             <ColumnDefinition Width="150"/>
                                                                             <ColumnDefinition Width="60"/>
                                                                         </Grid.ColumnDefinitions>
                                                                         <Image Source="{Binding Path=BindingContext.IconAudioPlayer, Source={x:Reference ImageAllegato}}" HeightRequest="50" WidthRequest="50" VerticalOptions="Center" HorizontalOptions="Center">
                                                                             <Image.GestureRecognizers>
                                                                                 <TapGestureRecognizer Command="{Binding Path=BindingContext.PlayAudioCommand, Source={x:Reference ImageAllegato}}" CommandParameter="{Binding PathDoc}" NumberOfTapsRequired="1"></TapGestureRecognizer>
                                                                             </Image.GestureRecognizers>
                                                                         </Image>
                                                                         <StackLayout Grid.Column="1">
                                                                             <Label Text="{Binding TicksAudioPlayer}" TextColor="White" FontAttributes="Bold" HorizontalOptions="Center" />
                                                                             <Slider x:Name="SliderSongPlayDisplay" Value="{Binding PositionAudioPlayer}" HorizontalOptions="FillAndExpand" Minimum="0" Maximum="{Binding DurationAudioPlayer}" MinimumTrackColor="{StaticResource Primary}" ThumbColor="{StaticResource Primary}" />
                                                                         </StackLayout>
                                                                         <Image Grid.Column="2" Source="{Binding PathDoc, Converter={StaticResource URLtoThumbValueConverter}}" HorizontalOptions="Center"/>
                                                                     </Grid>
                                                                     <!--<Label Text="{Binding Thumb}"/>-->
                                                                     <!--<Image x:Name="ImageAllegato" Source="{Binding PathDoc, Converter={StaticResource URLtoThumbValueConverter}, ConverterParameter={Binding IsLinkWeb}}" HorizontalOptions="Center">-->
                                                                     <!--<Label Text="{Binding NomeDoc}" TextColor="Black" IsVisible="{Binding NomeDoc, Converter={StaticResource StringNullOrEmptyBoolConverter}}" Margin="2" FontAttributes="Bold" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand"/>-->
                                                                     <Image x:Name="ImageAllegato" HorizontalOptions="Center">
                                                                         <Image.Source>
                                                                             <MultiBinding Converter="{StaticResource URLtoThumbMultiValueConverter}">
                                                                                 <Binding Path="PathDoc" />
                                                                                 <Binding Path="IsLinkWeb" />
                                                                                 <Binding Path="Thumb" />
                                                                             </MultiBinding>
                                                                         </Image.Source>
                                                                         <Image.Triggers>
                                                                             <DataTrigger TargetType="Image" Binding="{Binding PathDoc, Converter={StaticResource IsAudioValueConverter}}" Value="True">
                                                                                 <Setter Property="IsVisible" Value="False" />
                                                                             </DataTrigger>
                                                                         </Image.Triggers>
                                                                         <Image.GestureRecognizers>
                                                                             <TapGestureRecognizer Command="{Binding Path=BindingContext.ZoomPhotoCommand, Source={x:Reference ImageAllegato}}" CommandParameter="{Binding PathDoc}" NumberOfTapsRequired="2"></TapGestureRecognizer>
                                                                         </Image.GestureRecognizers>
                                                                     </Image>
                                                                     <Label Text="{Binding NoteDoc}" TextColor="Black" IsVisible="{Binding NoteDoc, Converter={StaticResource StringNullOrEmptyBoolConverter}}" Margin="2" FontAttributes="Bold" HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand"/>
                                                                 </StackLayout>
                                                             </DataTemplate>
                                                         </BindableLayout.ItemTemplate>
                                                     </StackLayout>
                                                 </StackLayout>
                                             </Frame>
                                         </Grid>
                                     </SwipeView>
                                 </ViewCell>
                             </DataTemplate>
                         </ListView.ItemTemplate>
                     </ListView>
                 </StackLayout>
             </ScrollView>`
    
    

Expected Behavior

Actual Behavior

Basic Information

  • Version with issue: 5.0
  • Last known good version: 4.8
  • Platform Target Frameworks:
    • iOS:
    • Android: target framework API 29
    • UWP:
  • Android Support Library / AndroidX Version:
  • NuGet Packages:
  • Affected Devices:

Environment

Show/Hide Visual Studio info
Microsoft Visual Studio Community 2019
Versione 16.8.4
VisualStudio.16.Release/16.8.4+30907.101
Microsoft .NET Framework
Versione 4.8.04084

Edizione installata: Community

Visual C++ 2019   00435-60000-00000-AA142
Microsoft Visual C++ 2019

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools 2019   16.8.557.25636
ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services   16.1.0.2052803+84e121f1403378489b842e1797df2f3f5a49ac3c
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2019   16.8.557.25636
Per altre informazioni, vedere https://www.asp.net/

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.6.1000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   16.8.557.25636
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.1000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

Color Picker   1.0
Integrated Color Picker for Visual Studio IDE and Editor

Conveyor by Keyoti   1.0
Allows you to access your web applications from other machines, even if hosted on the development web server.

Cookiecutter   16.8.20241.2
Fornisce gli strumenti per la ricerca, la creazione di un'istanza e la personalizzazione dei modelli in formato Cookiecutter.

Entity Framework Core Power Tools   2.5
Adds useful design-time EF Core DbContext features to the Visual Studio Solution Explorer context menu. 



Estensione IntelliCode   1.0
Informazioni dettagliate sull'estensione IntelliCode di Visual Studio

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Fabric.DiagnosticEvents   1.0
Eventi di diagnostica di Fabric

Gestione pacchetti NuGet   5.8.1
Gestione pacchetti NuGet in Visual Studio. Per altre informazioni su NuGet, visitare il sito Web https://docs.nuget.org/

Microsoft Azure HDInsight Azure Node   2.6.1000.0
HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service   2.6.1000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service   2.6.1000.0
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node   1.0
Azure Stream Analytics Node under Azure Node

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools per contenitori   1.1
Consente di sviluppare, eseguire e convalidare applicazioni ASP.NET Core nell'ambiente di destinazione. Premere F5 per modificare l'applicazione direttamente in un contenitore senza debug oppure CTRL+F5 per modificare e aggiornare l'app senza ricompilare il contenitore.

Mono Debugging for Visual Studio   16.8.43 (00471f8)
Support for debugging Mono processes with Visual Studio.

Node.js Tools   1.5.20902.1 Commit Hash:b474efcb6f92db52a8f8e2e6a8cb9648476885cc
Aggiunge il supporto per sviluppare ed eseguire il debug di app Node.js in Visual Studio

Pacchetto di Microsoft Visual Studio VC   1.0
Pacchetto di Microsoft Visual Studio VC

Pacchetto host dell'adattatore di debug di Visual Studio Code   1.0
Livello di interoperabilità per l'hosting degli adattatori di debug di Visual Studio Code in Visual Studio

Procedure guidate di Microsoft Visual C++   1.0
Procedure guidate di Microsoft Visual C++

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Python   16.8.20241.2
Fornisce IntelliSense, progetti, modelli, debug, finestre interattive e altri supporti per gli sviluppatori Python.

Python - Supporto Conda   16.8.20241.2
Supporto Conda per progetti Python.

Python - Supporto Django   16.8.20241.2
Fornisce i modelli e l'integrazione per il framework Web Django.

Python - Supporto IronPython   16.8.20241.2
Fornisce i modelli e l'integrazione per i progetti basati su IronPython.

Python - Supporto profilatura   16.8.20241.2
Supporto profilatura per progetti Python.

SQL Server Data Tools   16.0.62012.31170
Microsoft SQL Server Data Tools

Strumenti C#   3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd
Componenti di C# usati nell'IDE. A seconda del tipo e delle impostazioni del processo, è possibile che venga usata una versione diversa del compilatore.

Strumenti comuni di Azure   1.10
Fornisce servizi comuni da usare con Servizi mobili di Azure e gli strumenti di Microsoft Azure.

Strumenti del Servizio app di Azure versione 3.0.0   16.8.557.25636
Strumenti del Servizio app di Azure versione 3.0.0

Strumenti di Microsoft Azure   2.9
Strumenti di Microsoft Azure per Microsoft Visual Studio 2019 - versione 2.9.30924.1

Strumenti di Microsoft Azure Service Fabric per Visual Studio   16.0
Strumenti di Microsoft Azure Service Fabric per Visual Studio

Strumenti di recapito continuo Microsoft per Visual Studio   0.4
Consente di semplificare la configurazione delle pipeline Azure DevOps direttamente dall'IDE di Visual Studio.

Strumenti di Visual Basic   3.8.0-5.20604.10+9ed4b774d20940880de8df1ca8b07508aa01c8cd
Componenti di Visual Basic usati nell'IDE. A seconda del tipo e delle impostazioni del processo, è possibile che venga usata una versione diversa del compilatore.

Strumenti TypeScript   16.0.21016.2001
Strumenti TypeScript per Microsoft Visual Studio

SyncfusionXamarinMenu Extension   1.0
SyncfusionXamarinMenu Visual Studio Extension Detailed Info

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

Visual F# Tools   16.8.0-beta.20507.4+da6be68280c89131cdba2045525b80890401defd
Microsoft Visual F# Tools

Visual Studio Container Tools Extensions   1.0
Consente di visualizzare, gestire ed eseguire la diagnosi dei contenitori all'interno di Visual Studio.

Visual Studio Tools per contenitori   1.0
Visual Studio Tools per contenitori

Visual Studio Tools per Kubernetes   1.0
Visual Studio Tools per Kubernetes

VisualStudio.DeviceLog   1.0
Informazioni sul pacchetto

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.8.000.261 (d16-8@bb99248)
Estensione di Visual Studio per consentire lo sviluppo per Xamarin.iOS e Xamarin.Android.

Xamarin Designer   16.8.0.507 (remotes/origin/d16-8@e87b24884)
Estensione di Visual Studio per abilitare gli strumenti di Xamarin Designer in Visual Studio.

Xamarin Templates   16.8.112 (86385a3)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.1.0.26 (d16-8/a36ce73)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: 5e9cb6d
    Java.Interop: xamarin/java.interop/d16-8@79d9533
    ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000
    SQLite: xamarin/sqlite/3.32.1@1a3276b
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc


Xamarin.iOS and Xamarin.Mac SDK   14.8.0.3 (c51fabee8)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Build Logs

Screenshots

Reproduction Link

Workaround

@MarcoSal MarcoSal added s/unverified New report that has yet to be verified t/bug 🐛 labels Jan 14, 2021
@jsuarezruiz jsuarezruiz changed the title [Bug] [Bug] The specified child already has a parent Jan 14, 2021
@jsuarezruiz jsuarezruiz self-assigned this Jan 14, 2021
@jsuarezruiz jsuarezruiz added s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Jan 14, 2021
@jsuarezruiz
Copy link
Contributor

@MarcoSal Could you attach a sample where reproduce the issue?, could you share the exception trace?. I have done a quick test, but cannot reproduce the issue.

issue13399

@MarcoSal
Copy link
Author

MarcoSal commented Jan 15, 2021

when I delete an element it generates the error, except in case it is the last element ...
The project works fine on the iOS platform

in the quick test you show, always remove the last element. in this case the bug is not generated.
It is generated on Android when you remove an element that is not the last ...

@jsuarezruiz jsuarezruiz added e/3 🕒 3 and removed s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. s/unverified New report that has yet to be verified labels Jan 18, 2021
@jsuarezruiz jsuarezruiz added the in-progress This issue has an associated pull request that may resolve it! label Jan 18, 2021
@jsuarezruiz
Copy link
Contributor

@MarcoSal Ah, now, I can reproduce the issue. Will be fixed by #13439

@gaurav-bagga
Copy link

@jsuarezruiz Request you to please provide any update on this issue. I am also facing the same issue, I am attaching the log. The issue is on same lines on swipe I am deleting element inside an ObservableCollection and it results in app crashing.

Android.log

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/swipeview e/3 🕒 3 in-progress This issue has an associated pull request that may resolve it! p/Android t/bug 🐛
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants