Bug 26446 - Re-attaching a view with a Scrollview on Android causes this crash
Summary: Re-attaching a view with a Scrollview on Android causes this crash
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.1
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-01-27 04:36 UTC by Hugo Logmans
Modified: 2015-02-06 08:02 UTC (History)
4 users (show)

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


Attachments
Example project crashing (4.13 MB, application/zip)
2015-01-30 04:39 UTC, Hugo Logmans
Details


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:
Status:
RESOLVED FIXED

Description Hugo Logmans 2015-01-27 04:36:33 UTC
When I have a tabbed-like system where views are attached and detached to a contentview, the ScrollView on Android crashes out the moment this view is RE-attached (first time works fine). I can see the scrollviewrenderer is recreated, but I noticed the old one is not released (no release messages in custom renderer).

Java.Lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
01-27 10:23:13.025 D/Mono    (10746): DllImport attempting to load: '/system/lib/liblog.so'.
01-27 10:23:13.025 D/Mono    (10746): DllImport loaded library '/system/lib/liblog.so'.
01-27 10:23:13.025 D/Mono    (10746): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
01-27 10:23:13.025 D/Mono    (10746): Searching for '__android_log_print'.
01-27 10:23:13.025 D/Mono    (10746): Probing '__android_log_print'.
01-27 10:23:13.025 D/Mono    (10746): Found as '__android_log_print'.
01-27 10:23:13.040 I/MonoDroid(10746): UNHANDLED EXCEPTION:
01-27 10:23:13.050 I/MonoDroid(10746): Java.Lang.IllegalStateException: Exception of type 'Java.Lang.IllegalStateException' was thrown.
01-27 10:23:13.050 I/MonoDroid(10746): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00068>
01-27 10:23:13.050 I/MonoDroid(10746): at Android.Runtime.JNIEnv.CallNonvirtualVoidMethod (intptr,intptr,intptr,Android.Runtime.JValue[]) [0x00084] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:896
01-27 10:23:13.050 I/MonoDroid(10746): at Android.Views.ViewGroup.AddView (Android.Views.View) [0x00070] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/platforms/android-17/src/generated/Android.Views.ViewGroup.cs:1663
01-27 10:23:13.055 I/MonoDroid01-27 10:23:13.050 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.ScrollViewContainer.set_ChildView (Xamarin.Forms.View) <IL 0x00054, 0x00203>
01-27 10:23:13.050 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.ScrollViewRenderer.LoadContent () <IL 0x00011, 0x00083>
01-27 10:23:13.050 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.ScrollViewRenderer.SetElement (Xamarin.Forms.VisualElement) <IL 0x000ab, 0x0047b>
01-27 10:23:13.050 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement,Xamarin.Forms.Platform.Android.IVisualElementRenderer,Xamarin.Forms.Platform.Android.RendererPool,bool) <IL 0x00011, 0x000ff>
01-27 10:23:13.050 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement,Xamarin.Forms.VisualElement) <IL 0x00116, 0x00827>
01-27 10:23:13.050 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () <IL 0x0000d, 0x0008b>
01-27 10:23:13.065 I/MonoDroid(10746): at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr01-27 10:23:13.050 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<Xamarin.Forms.View>.SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager) <0x00083>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<Xamarin.Forms.View>.SetElement (Xamarin.Forms.View) <0x006a3>
01-27 10:23:13.065 I/MonoDro01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<Xamarin.Forms.View>.Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement) <0x0012b>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement) <IL 0x00022, 0x0013f>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement,Xamarin.Forms.Platform.Android.IVisualElementRenderer,Xamarin.Forms.Platform.Android.RendererPool,bool) <IL 0x00011, 0x000ff>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement,Xamarin.Forms.VisualElement) <IL 0x00116, 0x00827>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () <IL 0x0000d, 0x0008b>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<Xamarin.Forms.View>.SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager) <0x00083>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<Xamarin.Forms.View>.SetElement (Xamarin.Forms.View) <0x006a3>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<Xamarin.Forms.View>.Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement) <0x0012b>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.RendererFactory.GetRenderer (Xamarin.Forms.VisualElement) <IL 0x00022, 0x0013f>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement,Xamarin.Forms.Platform.Android.IVisualElementRenderer,Xamarin.Forms.Platform.Android.RendererPool,bool) <IL 0x00011, 0x000ff>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementPackager.OnChildAdded (object,Xamarin.Forms.ElementEventArgs) <IL 0x00014, 0x000eb>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Element.OnChildAdded (Xamarin.Forms.Element) <IL 0x00037, 0x00187>
01-27 10:23:13.055 I/MonoDroid(10746): at Xamarin.Forms.Layout.OnInternalAdded (Xamarin.Forms.View) <IL 0x00014, 0x000ef>
01-27 10:23:13.060 I/MonoDroid(10746): at Xamarin.Forms.Layout.InternalChildrenOnCollectionChanged (object,System.Collections.Specialized.NotifyCollectionChangedEventArgs) <IL 0x0008a, 0x0068b>
01-27 10:23:13.060 I/MonoDroid(10746): at System.Collections.ObjectModel.ObservableCollection`1<Xamarin.Forms.Element>.OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs) <0x000f7>
01-27 10:23:13.060 I/MonoDroid(10746): at System.Collections.ObjectModel.ObservableCollection`1<Xamarin.Forms.Element>.InsertItem (int,Xamarin.Forms.Element) <0x000d3>
01-27 10:23:13.060 I/MonoDroid(10746): at System.Collections.ObjectModel.Collection`1<Xamarin.Forms.Element>.Add (Xamarin.Forms.Element) <0x000c3>
01-27 10:23:13.060 I/MonoDroid(10746): at Xamarin.Forms.ContentView.set_Content (Xamarin.Forms.View) <IL 0x0004a, 0x0019f>
01-27 10:23:13.060 I/MonoDroid(10746): at FiscaalMemoApp.Controllers.TabView.OnTabPropertyChanged (object,System.ComponentModel.PropertyChangedEventArgs) [0x00064] in z:\development\FiscaalMemoApp\FiscaalMemoApp\FiscaalMemoApp\Controllers\TabView.cs:290
01-27 10:23:13.060 I/MonoDroid(10746): at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs (object,System.ComponentModel.PropertyChangedEventArgs) <IL 0x00027, 0x00067>
01-27 10:23:13.060 I/MonoDroid(10746): at FiscaalMemoApp.Controllers.Tab.RaisePropertyChanged (string) [0x0000e] in z:\development\FiscaalMemoApp\FiscaalMemoApp\FiscaalMemoApp\Controllers\ITabView.cs:127
01-27 10:23:13.060 I/MonoDroid(10746): at FiscaalMemoApp.Controllers.Tab.set_Selected (bool) [0x0001a] in z:\development\FiscaalMemoApp\FiscaalMemoApp\FiscaalMemoApp\Controllers\ITabView.cs:103
01-27 10:23:13.060 I/MonoDroid(10746): at FiscaalMemoApp.Controllers.Tab.<get_TabImage>b__2 () [0x0000b] in z:\development\FiscaalMemoApp\FiscaalMemoApp\FiscaalMemoApp\Controllers\ITabView.cs:147
01-27 10:23:13.060 I/MonoDroid(10746): at Xamarin.Forms.Command/<>c__DisplayClass2.<.ctor>b__0 (object) <IL 0x00006, 0x00057>
01-27 10:23:13.065 I/MonoDroid(10746): at Xamarin.Forms.Command.Execute (object) <IL 0x00007, 0x0005b>
01-27 10:23:13.065 I/MonoDroid(10746): at Xamarin.Forms.TapGestureRecognizer.SendTapped (Xamarin.Forms.View) <IL 0x0001f, 0x0014b>
01-27 10:23:13.065 I/MonoDroid(10746): at Xamarin.Forms.Platform.Android.VisualElementRenderer`1<Xamarin.Forms.Image>.Android.Views.View.IOnClickListener.OnClick (Android.Views.View) <0x0031f>
01-27 10:23:13.065 I/MonoDroid(10746): at Android.Views.View/IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (intptr,intptr,intptr) [0x00011] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.21-series/49a04b96/source/monodroid/src/Mono.Android/platforms/android-17/src/generated/Android.Views.View.cs:1791
01-27 10:23:13.065 I/MonoDroid(10746): at (wrapper dynamic-method) object.4f62ffad-f7b8-463b-a400-8c97c6c25a30 (intptr,intptr,intptr) <IL 0x00017, 0x00043>
01-27 10:23:13.065 I/MonoDroid(10746):   --- End of managed exception stack trace ---
01-27 10:23:13.065 I/MonoDroid(10746): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
01-27 10:23:13.065 I/MonoDroid(10746): 	at android.view.ViewGroup.addViewInner(ViewGroup.java:3672)
01-27 10:23:13.065 I/MonoDroid(10746): 	at android.view.ViewGroup.addView(ViewGroup.java:3543)
01-27 10:23:13.065 I/MonoDroid(10746): 	at android.view.ViewGroup.addView(ViewGroup.java:3488)
01-27 10:23:13.065 I/MonoDroid(10746): 	at android.view.ViewGroup.addView(ViewGroup.java:3464)
01-27 10:23:13.065 I/MonoDroid(10746): 	at xamarin.forms.platform.android.VisualElementRenderer_1.n_onClick(Native Method)
01-27 10:23:13.065 I/MonoDroid(10746): 	at xamarin.forms.platform.android.VisualElementRenderer_1.onClick(VisualElementRenderer_1.java:54)
01-27 10:23:13.070 I/MonoDroid(10746): 	at android.view.View.performClick(View.java:4232)
01-27 10:23:13.070 I/MonoDroid(10746): 	at android.view.View$PerformClick.run(View.java:17318)
01-27 10:23:13.070 I/MonoDroid(10746): 	at android.os.Handler.handleCallback(Handler.java:615)
01-27 10:23:13.070 I/MonoDroid(10746): 	at android.os.Handler.dispatchMessage(Handler.java:92)
01-27 10:23:13.070 I/MonoDroid(10746): 	at android.os.Looper.loop(Looper.java:137)
01-27 10:23:13.070 I/MonoDroid(10746): 	at android.app.ActivityThread.main(ActivityThread.java:4921)
01-27 10:23:13.070 I/MonoDroid(10746): 	at java.lang.reflect.Method.invokeNative(Native Method)
01-27 10:23:13.070 I/MonoDroid(10746): 	at java.lang.reflect.Method.invoke(Method.java:511)
01-27 10:23:13.070 I/MonoDroid(10746): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
01-27 10:23:13.070 I/MonoDroid(10746): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
01-27 10:23:13.070 I/MonoDroid(10746): 	at dalvik.system.NativeStart.main(Native Method)
Comment 1 Hugo Logmans 2015-01-27 06:48:24 UTC
Some further investigations:
- I am completely unable to make sure the renderer is ever freed. I created a custom renderer of the scrollview. Setting all links to null never garbages the element.
- When I recreate the view instead of reattaching it, this error still happens.
Comment 2 Abhishek 2015-01-29 10:50:49 UTC
I have tried this issue and unable to reproduce the reported behavior at my ends.

Steps to reproduce:
1. Create a sample xamarin form application.
2. Add TabbedPage.xaml in the solution.
3. Create two page name as Page1 and Page2.
4. In the Page1.xaml create scrollview with the help xml code.
5. In the Page2.xaml create scrollview with the help of coding.
6. Run the application in the emulator.

Screencast: http://www.screencast.com/t/ckO5A3nnf

If I did not follow the correct steps to reproduce the reported behavior then Could you please attach a sample project? So that I can reproduce this issue at my end.

Build Info:

=== Xamarin Studio ===

Version 5.7.1 (build 15)
Installation UUID: 93e693b0-b53d-40f4-b29c-b61ff5cbe892
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.iOS ===

Version: 8.6.1.20 (Business Edition)
Hash: 3b3ef43
Branch: 
Build date: 2015-01-24 09:42:21-0500

=== Xamarin.Android ===

Version: 5.0.0.17 (Business Edition)
Android SDK: /Users/xamarin23/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin.Mac ===

Version: 1.10.0.18 (Business Edition)

=== Build Information ===

Release ID: 507010015
Git revision: ce24e991948c7f3d88b0194a14fc1996d848ef51
Build date: 2015-01-26 16:42:20-05
Xamarin addins: 6895e3222bfa6910524708aa0633ff3db99bc3a0

=== Operating System ===

Mac OS X 10.10.0
Darwin 800BC.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 3 Hugo Logmans 2015-01-30 04:36:16 UTC
Thanks Abishek for your effort. Attaching a reproducable project. I hope you can find a workaround, because at the moment my project is ready except for this showstopper.

One strange thing is that one of the alternatives I present in this project, does work in this project, and not in my production project. I will look into this because there might be more to this problem than this basic error alone.

Xamarin Studio
Version 5.7 (build 661)
Installation UUID: e4393e51-258d-4d76-9b50-a863b4a8ff36
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

Apple Developer Tools
Xcode 6.1.1 (6611)
Build 6A2008a

Xamarin.iOS
Version: 8.6.0.51 (Business Edition)
Hash: dfb682f
Branch: 
Build date: 2015-01-08 13:39:32-0500

Xamarin.Android
Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/hlogmans/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

Xamarin.Mac
Not Installed

Build Information
Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

Operating System
Mac OS X 10.10.1
Darwin MacBook-Pro-van-Hugo.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 4 Hugo Logmans 2015-01-30 04:39:39 UTC
Created attachment 9576 [details]
Example project crashing

See in the project for some alternatives and their result.
Comment 5 Hugo Logmans 2015-01-30 11:35:21 UTC
I have replaced all code with a listview instead of the scrollview with more advanced logic, and that works well. So for me the urgency is low now.
Comment 6 Hugo Logmans 2015-01-31 03:56:26 UTC
I have added the requested info
Comment 7 Abhishek 2015-02-02 06:34:38 UTC
I have tried this issue and able to reproduce the reported behavior at my end.

Steps to reproduce:
1. Download the sample form the given attachment.
2. Run the Application on the  emulator/Device.
3. Click on "Click to Switch" Button .It will switch and show red screen .
4.Again click on "Click to Switch" Button.It will not switch and give exception.

When click on "Click to switch" button it giving exception for android application on emulator/device. However, for iOS application it is working fine.

screencast: http://www.screencast.com/t/mibiaZ0Ua
Application Output: https://gist.github.com/AkhileshKumar01/933da4ba5b708bafdb53
Exception Output: https://gist.github.com/AkhileshKumar01/7f5889e85c0e75d1313c

Build Info:

Xamarin.Forms 1.3.2.6313-pre3
Xamarin.Forms 1.3.1.6296

=== Xamarin Studio ===

Version 5.7.1 (build 14)
Installation UUID: 93e693b0-b53d-40f4-b29c-b61ff5cbe892
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.Mac ===

Version: 1.12.0.4 (Business Edition)

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/xamarin23/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin.iOS ===

Version: 8.6.0.51 (Business Edition)
Hash: dfb682f
Branch: 
Build date: 2015-01-08 13:39:32-0500

=== Build Information ===

Release ID: 507010014
Git revision: a4dd61ad7f8b3695be4b17bcb5c3ae6b81438cf7
Build date: 2015-01-19 15:21:09-05
Xamarin addins: 081208fe3bbf40e24a562867c6c7fba20a9b94b6

=== Operating System ===

Mac OS X 10.10.0
Darwin 800BC.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 8 Jason Smith [MSFT] 2015-02-06 08:02:14 UTC
We can no longer reproduce this in 1.3.4