Bug 34936 - Unable to activate instance of type Xamarin.Forms.Platform.Android.ButtonDrawable from native handle
Summary: Unable to activate instance of type Xamarin.Forms.Platform.Android.ButtonDraw...
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.5.0
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-10-16 06:45 UTC by Prashant Cholachagudda
Modified: 2017-06-17 01:12 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 Prashant Cholachagudda 2015-10-16 06:45:17 UTC
Customer is getting the following exception in their production code: (using Xamarin Forms 1.5.0.6447

System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Platform.Android.ButtonDrawable from native handle 88800019
at Java.Interop.TypeManager.CreateInstance(intptr_Android.Runtime.JniHandleOwnership_System.Type.args:1337)
at Java.Lang.Object.GetObject(intptr_Android.Runtime.JniHandleOwnership_System.Type.args:1337)
at Java.Lang.Object._GetObject<Android.Graphics.Drawables.Drawable>(intptr_Android.Runtime.JniHandleOwnership.args:1337)
at Java.Lang.Object.GetObject<Android.Graphics.Drawables.Drawable>(intptr_Android.Runtime.JniHandleOwnership.args:1337)
at Java.Lang.Object.GetObject<Android.Graphics.Drawables.Drawable>(intptr_intptr_Android.Runtime.JniHandleOwnership.args:1337)
at Android.Graphics.Drawables.Drawable.n_IsStateful(intptr_intptr.args:1337)

However it is not reproducible in the new projects.
Comment 1 David Johnson 2015-10-16 10:48:29 UTC
I believe the issue is that the Xamarin.Forms.Platform.Android.ButtonDrawable class inherits from Java.Lang.Object but does not implement a constructor that accepts (IntPtr, JniHandleOwnership) arguments, as described in this StackOverflow thread: http://stackoverflow.com/questions/10593022/monodroid-error-when-calling-constructor-of-custom-view-twodscrollview/10603714#10603714 <http://stackoverflow.com/questions/10593022/monodroid-error-when-calling-constructor-of-custom-view-twodscrollview/10603714#10603714>.

This is the key concept from that thread:

The Android Callable Wrapper (ACW) <http://docs.xamarin.com/android/advanced_topics/architecture/android_callable_wrappers>'s constructor is invoked by Java and is responsible for creating the peer C# instance and mapping the Java instance to the C# instance <http://docs.xamarin.com/android/advanced_topics/garbage_collection#Cross-VM_Object_Collections>. However, if a virtual method is invoked from the Java constructor, then the method will be dispatched before there is a C# instance to invoke the method upon!


When this happens, the Mono runtime will attempt to invoke the (IntPtr, JniHandleOwnership) constructor on the C# class to establish the mapping with the corresponding Java class. The NotSupportedException indicates that the C# class is missing this constructor.
Comment 2 Caan Mee 2015-11-02 09:36:46 UTC
I'm getting this also when I inherit from ViewRenderer to create a custom renderer.

I have no chance to provide the missing constructor, since I can't access the constructor in the FormsViewGroup because the VisualElementRenderer default constructor hides it.

This is really a major issue to us.
Comment 3 David Johnson 2015-11-24 10:45:40 UTC
It's been a month. No progress?
Comment 4 David Johnson 2016-01-06 19:40:53 UTC
Now it's been almost 3 months. Still no progress?
Comment 5 Andrew 2016-03-24 00:14:29 UTC
I too would like this to be addressed.
Comment 6 adrianknight89 2016-04-26 03:25:54 UTC
I created a repro of a similar issue in another thread. Looks like many people are affected by this problem.

Please see: https://bugzilla.xamarin.com/show_bug.cgi?id=40692
Comment 7 Samantha Houts [MSFT] 2016-06-17 16:42:04 UTC
Do you continue to experience this issue after updating Xamarin.Android?
Comment 8 Cody Beyer (MSFT) 2016-08-31 21:43:13 UTC
@Samantha

Reports that this is still occurring on the latest Xamarin.Android:

=== Xamarin Studio Enterprise ===

Version 6.0.2 (build 73)
Installation UUID: c6cc2bf2-3d75-4e51-bb1f-b12a2a84f591
Runtime:
Mono 4.4.2 (mono-4.4.0-branch-c7sr1/f72fe45) (64-bit)
GTK+ 2.24.23 (Raleigh theme)

Package version: 404020011

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.3.1 (10188.1)
Build 7D1014

=== Xamarin.iOS ===

Version: 9.8.2.22 (Visual Studio Enterprise)
Hash: f37444a
Branch: cycle7-sr1
Build date: 2016-07-28 12:17:02-0400

=== Xamarin.Android ===

Version: 6.1.2.21 (Visual Studio Enterprise)
Android SDK: /Users/mccorma/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
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)
5.1 (API level 22)
6.0 (API level 23)

SDK Tools Version: 25.2.2
SDK Platform Tools Version: 24.0.2
SDK Build Tools Version: 23.0.3

Java SDK: /usr
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.8.2.22 (Visual Studio Enterprise)

=== Xamarin Inspector ===

Version: 0.9.0.14
Hash: 4d868da
Branch: master
Build date: Mon Jun 13 19:14:13 UTC 2016

=== Build Information ===

Release ID: 600020073
Git revision: a6f7a24a9723a2d4f5d33c176615b0d44703ab5b
Build date: 2016-07-26 13:36:15-04
Xamarin addins: f5acb37866a0141bc5ddbe95118f18dae4014568
Build lane: monodevelop-lion-cycle7-sr1
Comment 9 David Ortinau [MSFT] 2017-06-17 01:12:16 UTC
I'm not able to reproduce this issue as described. If this is still occuring, please reopen the issue and include a project that demonstrates this issue with explicit steps to observe the behavior.