Bug 58357 - TypeManager.CreateProxy - Unable to activate instance of type Xamarin.Forms.Platform.Android.CarouselPageAdapter from native handle
Summary: TypeManager.CreateProxy - Unable to activate instance of type Xamarin.Forms.P...
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.5
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-07-25 09:42 UTC by Faizan
Modified: 2017-10-31 17:53 UTC (History)
7 users (show)

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

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 NOT_REPRODUCIBLE

Description Faizan 2017-07-25 09:42:59 UTC
I am unable to reproduce this bug but It seems to be occurring and getting logged in hockey app crashes.

TypeManager.CreateProxy
android.runtime.JavaProxyThrowable: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.CarouselPageAdapter from native handle 0xbe89acac (key_handle 0x5c38930). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.CarouselPageAdapter::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.

Xamarin caused by: android.runtime.JavaProxyThrowable: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.CarouselPageAdapter from native handle 0xbe89acac (key_handle 0x5c38930). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.CarouselPageAdapter::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
   --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00058] in <68e5881610ef44d893a574916711c196>:0 
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00138] in <68e5881610ef44d893a574916711c196>:0 
   --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x001b0] in <68e5881610ef44d893a574916711c196>:0 
  at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000e5] in <68e5881610ef44d893a574916711c196>:0 
  at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x0001a] in <68e5881610ef44d893a574916711c196>:0 
  at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <68e5881610ef44d893a574916711c196>:0 
  at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <68e5881610ef44d893a574916711c196>:0 
  at Android.Support.V4.View.ViewPager+IOnPageChangeListenerInvoker.n_OnPageScrollStateChanged_I (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 state) [0x00000] in <8e156317206449fc8cae6c77ed391368>:0 
  at (wrapper dynamic-method) System.Object:85b52e34-f351-4514-bfc0-fcd5f6dfeea1 (intptr,intptr,int)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.CarouselPageAdapter.n_onPageScrollStateChanged(Native Method)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.CarouselPageAdapter.onPageScrollStateChanged(CarouselPageAdapter.java:77)
	at android.support.v4.view.ViewPager.dispatchOnScrollStateChanged(ViewPager.java:1984)
	at android.support.v4.view.ViewPager.setScrollState(ViewPager.java:497)
	at android.support.v4.view.ViewPager$3.run(ViewPager.java:272)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:920)
	at android.view.Choreographer.doCallbacks(Choreographer.java:695)
	at android.view.Choreographer.doFrame(Choreographer.java:628)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:906)
	at android.os.Handler.handleCallback(Handler.java:739)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:158)
	at android.app.ActivityThread.main(ActivityThread.java:7224)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Comment 1 Jon Douglas [MSFT] 2017-07-25 17:03:58 UTC
Hi faizan,

Based on the error message, it seems that this renderer in the source control is missing the following constructor:

ctor(System.IntPtr, Android.Runtime.JniHandleOwnership)

You can see other examples of this in the Forms source:

https://github.com/xamarin/Xamarin.Forms/search?utf8=%E2%9C%93&q=System.IntPtr%2C+Android.Runtime.JniHandleOwnership&type=

However I don't see it within the failing renderer:

https://github.com/xamarin/Xamarin.Forms/blob/425fafb05723a299a5eaa0f6d801f87bdf7141fa/Xamarin.Forms.Platform.Android/Renderers/CarouselPageAdapter.cs

I believe this can be explained a bit better by this Stack Overflow post:

https://stackoverflow.com/questions/10593022/monodroid-error-when-calling-constructor-of-custom-view-twodscrollview/10603714#10603714

I am moving this bug to Xamarin.Forms for better visibility.
Comment 2 Faizan 2017-07-26 07:32:59 UTC
HI Jon Douglas,

Thank you so much for the quick response and so sorry for my lack of explanation and not to put my findings against the issue.

So is it confirmed as a bug that we can expect to be fixed in upcoming xamarin.forms release? 

Meanwhile, is there a work around to avoid this issue?
Comment 3 Jimmy [MSFT] 2017-07-31 21:14:02 UTC
Hi Faizan,

We can add the constructor as mentioned in comment 1, however that would only mask the actual issue. This exception usually indicates that something in the Java side is trying to access a .NET object _after_ it's been collected. This is the real issue we would like to fix if possible.

What devices are you seeing this issue reported on? Is there any common factor between them, for example low memory capacity or Android version? What version of Xamarin.Forms are you using?
Comment 4 Stefano 2017-08-31 14:51:40 UTC
Hi, 
same bug for me, this is the stacktrace:

Xamarin caused by: android.runtime.JavaProxyThrowable: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.CarouselPageAdapter from native handle 0xbeedfe0c (key_handle 0x25a48702). ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Platform.Android.CarouselPageAdapter::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
   --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateProxy (System.Type type, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00058] in <ce1bf50ed93c4ac3916170e9d6605a74>:0 
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x00138] in <ce1bf50ed93c4ac3916170e9d6605a74>:0 
   --- End of inner exception stack trace ---
  at Java.Interop.TypeManager.CreateInstance (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type targetType) [0x001b0] in <ce1bf50ed93c4ac3916170e9d6605a74>:0 
  at Java.Lang.Object.GetObject (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer, System.Type type) [0x000e5] in <ce1bf50ed93c4ac3916170e9d6605a74>:0 
  at Java.Lang.Object._GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x0001a] in <ce1bf50ed93c4ac3916170e9d6605a74>:0 
  at Java.Lang.Object.GetObject[T] (System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00000] in <ce1bf50ed93c4ac3916170e9d6605a74>:0 
  at Java.Lang.Object.GetObject[T] (System.IntPtr jnienv, System.IntPtr handle, Android.Runtime.JniHandleOwnership transfer) [0x00006] in <ce1bf50ed93c4ac3916170e9d6605a74>:0 
  at Android.Support.V4.View.ViewPager+IOnPageChangeListenerInvoker.n_OnPageScrollStateChanged_I (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 state) [0x00000] in <27c17fe440cf491ba8255bcefade6e02>:0 
  at (wrapper dynamic-method) System.Object:fb8d1152-ec1e-4947-8c67-7101b108bd45 (intptr,intptr,int)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.CarouselPageAdapter.n_onPageScrollStateChanged(Native Method)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.CarouselPageAdapter.onPageScrollStateChanged(CarouselPageAdapter.java:77)
	at android.support.v4.view.ViewPager.dispatchOnScrollStateChanged(ViewPager.java:1879)
	at android.support.v4.view.ViewPager.setScrollState(ViewPager.java:460)
	at android.support.v4.view.ViewPager.access$000(ViewPager.java:91)
	at android.support.v4.view.ViewPager$3.run(ViewPager.java:253)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
	at android.view.Choreographer.doCallbacks(Choreographer.java:580)
	at android.view.Choreographer.doFrame(Choreographer.java:549)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
	at android.os.Handler.handleCallback(Handler.java:739)
	at android.os.Handler.dispatchMessage(Handler.java:95)
	at android.os.Looper.loop(Looper.java:135)
	at android.app.ActivityThread.main(ActivityThread.java:5753)
	at java.lang.reflect.Method.invoke(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:372)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)

I'm receiving a lot of this on hockeyapp from almost all android device models and android version from 4.1 to 7.0.
Xamarin.Forms is v2.3.4.231.
Comment 5 Paul DiPietro [MSFT] 2017-10-31 17:53:12 UTC
Due to no further reports or a reproduction project, this will be closed. Please reopen this with a reproduction attached if the issue still occurs as of the latest stable and/or prerelease builds of Forms.