CarouselView: [Android] Blocking exception with latest Xamarin.Forms 3.5 when leaving a page (worked on 3.4)

Description After updating to XF 3.5, an exception occurs every time a NavigationPage having at least a Carousel (within a ContentPage) as part of its navigation stack leaves the visual tree.

Platform Android (I’ve tried with API 23 and 26)

Steps to reproduce

  1. Open a modal content page A (with a carousel) inside a navigation page
  2. Close the modal page A

Alternative flow:

  1. Within a top level navigation page push a content page A containing a carousel
  2. Replace the root page with a new page or navigation page

Result

System.NotSupportedException: Unable to activate instance of type Com.ViewPagerIndicator.CirclePageIndicator from native handle 0xff91625c (key_handle 0x379aca3). ---> System.MissingMethodException: No constructor found for Com.ViewPagerIndicator.CirclePageIndicator::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
  at Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.
  at java.lang.Error: Java callstack:
  at at md5cb1a4bab49bfe17ad6c0290694c1d310.CirclePageIndicator.n_onSaveInstanceState(Native Method)
  at at md5cb1a4bab49bfe17ad6c0290694c1d310.CirclePageIndicator.onSaveInstanceState(CirclePageIndicator.java:85)
  at at android.view.View.dispatchSaveInstanceState(View.java:14669)
  at at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:3093)
  at at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:3099)
  at at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:3099)
  at at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:3099)
  at at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:3099)
  at at android.view.ViewGroup.dispatchSaveInstanceState(ViewGroup.java:3099)
  at at android.view.View.saveHierarchyState(View.java:14652)
  at at android.support.v4.app.FragmentManagerImpl.saveFragmentViewState(FragmentManager.java:2859)
  at at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1500)
  at at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750)
  at at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:792)
  at at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590)
  at at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377)
  at at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332)
  at at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239)
  at at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:781)
  at at mono.java.lang.RunnableImplementor.n_run(Native Method)
  at at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
  at at android.os.Handler.handleCallback(Handler.java:739)
  at at android.os.Handler.dispatchMessage(Handler.java:95)
  at at android.os.Looper.loop(Looper.java:148)
  at at android.app.ActivityThread.main(ActivityThread.java:5417)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00055] in <ea97b6d670fe4c1ba9dadb89b2fa0103>:0
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00116] in <ea97b6d670fe4c1ba9dadb89b2fa0103>:0
  --- End of inner exception stack trace ---

Sample project I’ve created a sample minimal project exercising both flows. You can find it here: https://drive.google.com/open?id=14TiTnEuucfs28E2lKd0SJAbHZ_V397uF

I’m guessing that that the save/restore override in this class is causing the problem: https://github.com/alexrainman/CirclePageIndicator/blob/master/Com.ViewPagerIndicator/CirclePageIndicator.cs

Thanks for this great component!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 72 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Guys, i am very close to release a new version and it will be compatible with XF 3.5 and with lot of new functionality.

In case you are like me and you couldn’t wait, you can use this instead: https://github.com/AndreiMisiukevich/CardView

I think it has some benefits. It doesn’t use an Android specific implementation for the carouselview, it achieves it with built in xamarin layouts. So I think it would be more resilient to change. I just downloaded it and changed my nuget packages over and everything came to life.

Plus you get a choice of more visual flair (card view or carousel view for instance). I like it.

Any news on a release? As you said it was coming soon I postponed my client’s release but we’ve reached the end of the the week without any news. Any idea of a release date please?

I think by end of week.

I am back! Releasing new version in the next 2 weeks. This issue will be corrected.

@alexrainman Update on this?

I am almost ready for a new release but have been traveling. Will keep you guys posted.

Sorry guys, i have been sick. Will come back to the project later today and i expect to release by end of week.

@NiknakSi the answer is yes. I am into CarouselView development and i expect to release new version in couple of weeks.

@alexrainman also like to know when we can at hope to maybe have something on this?

It has taken me more than expected to correct all the issues and add all the new functionality i wanted to add but the carousel is alive and will be out soon.

@Phenek i am just fine 😁

@alexrainman After Updating XF4.0.0.425677 and Changed the Target Framework ( Android 8.1 ), Still i am facing the same issue and getting exception like Unable to activate instance of type Com.ViewPagerIndicator.CirclePageIndicator from native handle 0x7fe4ce06c4 . Can you please provide us the solution.

Downgraded to XF 3.4 and everything is ok

Hi @alexrainman , Do we have any final solution for this issue, kindly we need your help?

I got it working by changing my Target Framework to be Android 9.0 and re-installing the support packages using the following in Package manager: Update-Package Xamarin.Android.Support.v4 -Reinstall

I also resinstalled the Xamarin.Android.Support.v7 packages I had installed. I ended up with some additional packages in project that were not there before, so maybe this was the probelm. Hope it helps someone else.

Thanks @TohWei , I’ve done the same as you and it also fix the bug. Thanks all

I just added the Xamarin.Android.CirclePageIndicator (Com.ViewPagerIndicator CirclePageIndicator for Xamarin.Android.). version 1.0.3. to my Android project.

It has fixed my problem. It is working now. Thanks.

Also waiting for this, so would be curious to hear about a release @alexrainman 😃

@alexrainman any idea when we can expect the update? I know your busy, even if its a few weeks so I know how to plan. Thank you

The same but he respond on this sub-project (https://github.com/alexrainman/CirclePageIndicator/issues/1) He will release soon a update i think