Bug 29149 - IllegalStateException exception on moving a Control to another container
Summary: IllegalStateException exception on moving a Control to another container
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.4.1
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-04-16 06:54 UTC by Prashant Cholachagudda
Modified: 2016-04-08 19:45 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Testcase (2.03 KB, application/octet-stream)
2015-04-16 06:54 UTC, Prashant Cholachagudda

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Prashant Cholachagudda 2015-04-16 06:54:33 UTC
Created attachment 10784 [details]

When we move a control from one container to another. If there is a ScrollView involved, the application crashes with an exception, Note that it happens only on Android:
Java.Lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  at at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00068>
  at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00084] in /Users/builder/data/lanes/1353/86274adf/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:896
  at Android.Views.ViewGroup.AddView (Android.Views.View) [0x00070] in /Users/builder/data/lanes/1353/86274adf/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.ViewGroup.cs:1968
  at at Xamarin.Forms.Platform.Android.ScrollViewContainer.set_ChildView (Xamarin.Forms.View) <IL 0x00054, 0x00207>
  at at Xamarin.Forms.Platform.Android.ScrollViewRenderer.LoadContent () <IL 0x00011, 0x00083>
  at at Xamarin.Forms.Platform.Android.ScrollViewRenderer.SetElement (Xamarin.Forms.VisualElement) <IL 0x000ab, 0x00493>
  at at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement) <IL 0x00022, 0x0013f>
  at at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement,Xamarin.Forms.Platform.Android.IVisualElementRenderer,Xamarin.Forms.Platform.Android.RendererPool,bool) <IL 0x00011, 0x000ff>
  at at Xamarin.Forms.Platform.Android.VisualElementPackager.OnChildAdded (object,Xamarin.Forms.ElementEventArgs) <IL 0x00014, 0x000eb>
  at at Xamarin.Forms.Element.OnChildAdded (Xamarin.Forms.Element) <IL 0x00037, 0x00187>
  at at Xamarin.Forms.Layout.OnInternalAdded (Xamarin.Forms.View) <IL 0x00014, 0x000f3>
  at at Xamarin.Forms.Layout.InternalChildrenOnCollectionChanged (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs) <IL 0x0008a, 0x0068b>
  at at (wrapper delegate-invoke) <Module>.invoke_void_object_NotifyCollectionChangedEventArgs (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs) <IL 0x00027, 0x00067>
  at at (wrapper delegate-invoke) <Module>.invoke_void_object_NotifyCollectionChangedEventArgs (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs) <IL 0x00027, 0x00067>
  at at (wrapper delegate-invoke) <Module>.invoke_void_object_NotifyCollectionChangedEventArgs (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs) <IL 0x00027, 0x00067>
  at at System.Collections.ObjectModel.ObservableCollection`1<Xamarin.Forms.Element>.OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs) <0x000f7>
  at at System.Collections.ObjectModel.ObservableCollection`1<Xamarin.Forms.Element>.InsertItem (int,Xamarin.Forms.Element) <0x000d3>
  at at System.Collections.ObjectModel.Collection`1<Xamarin.Forms.Element>.Add (Xamarin.Forms.Element) <0x000c3>
  at at Xamarin.Forms.ObservableWrapper`2<Xamarin.Forms.Element, Xamarin.Forms.View>.Add (Xamarin.Forms.View) <0x00203>
  at FormsTestApp.Class1/<XamarinMoveViewTest>c__AnonStorey0.<>m__0 (object,System.EventArgs) [0x00054] in /Users/prashantvc/Projects/FormsTestApp/FormsTestApp/EmptyClass.cs:97
  at at Xamarin.Forms.Button.Xamarin.Forms.IButtonController.SendClicked () <IL 0x00027, 0x0014f>
  at at Xamarin.Forms.Platform.Android.ButtonRenderer/ButtonClickListener.OnClick (Android.Views.View) <IL 0x00015, 0x00113>
  at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/1353/86274adf/source/monodroid/src/Mono.Android/platforms/android-21/src/generated/Android.Views.View.cs:1987
  at at (wrapper dynamic-method) object.26c27603-1575-4951-be52-d3ce5cddd48b (intptr,intptr,intptr) <IL 0x00017, 0x00043>
Comment 1 Chris King 2015-05-27 16:10:02 UTC
Jarle, thanks for submitting this issue. Please help us by attaching a solution containing a reduced reproduction to the bug by starting with a clean Xamarin.Forms project and adding just the code necessary to demonstrate the issue. If you'd do this for us we would very much appreciate it. 

Warm regards,
Xamarin Forms Team
Comment 2 Samantha Houts [MSFT] 2016-04-08 19:45:08 UTC
Thank you for your bug report. As we have not received the information requested, we cannot properly triage your bug and are marking it resolved.

Warm regards,
Xamarin Forms Team