Bug 20606 - Xam 3.1 Alpha: Custom Java Objects in C# cannot be constructed
Summary: Xam 3.1 Alpha: Custom Java Objects in C# cannot be constructed
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.14.0
Hardware: PC Windows
: Highest blocker
Target Milestone: 4.14.0
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2014-06-15 18:58 UTC by T.J. Purtell
Modified: 2014-07-07 09:36 UTC (History)
4 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:
VERIFIED FIXED

Description T.J. Purtell 2014-06-15 18:58:51 UTC
Using Xamarin for Android 4.1 alpha, attempting to instantiate a custom java object causes a crash inside the base class constructor.

You can see a demonstration of the error using this project
https://bitbucket.org/tpurtell/xam-3.1-alpha-custom-java-object-fail

>	0x21 in System.Diagnostics.Debugger.Mono_UnhandledException_internal	C#
>	0x1 in System.Diagnostics.Debugger.Mono_UnhandledException	C#
>	0x26 in object.6286e64b-04dd-4525-bf1f-df492dd8a816	C#
>	0x62 in System.Reflection.MonoMethod.Invoke	C#
>	0x6 in System.Reflection.MethodBase.Invoke	C#
>	0x90 in Android.Runtime.JNIEnv.CreateDynamicCallback at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.14-series/88db51a7/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:107,4	C#
>	0x1ED in Android.Runtime.JNIEnv.RegisterJniNatives at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.14-series/88db51a7/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:148,6	C#
>	0x30 in Android.Runtime.JNIEnv.AllocObject at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.14-series/88db51a7/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:113,4	C#
>	0x8 in Android.Runtime.JNIEnv.AllocObject at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.14-series/88db51a7/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:254,5	C#
>	0xB in Android.Runtime.JNIEnv.StartCreateInstance at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.14-series/88db51a7/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.cs:279,5	C#
>	0x2E in Java.Lang.Object..ctor at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.14-series/88db51a7/source/monodroid/src/Mono.Android/src/Java.Lang/Object.cs:71,4	C#
>	0x1 in App2.MyObject..ctor at c:\Users\tj\Documents\Visual Studio 2013\Projects\App2\App2\MainActivity.cs:37,-1	C#
> 	0x4D in App2.MainActivity.OnCreate at c:\Users\tj\Documents\Visual Studio 2013\Projects\App2\App2\MainActivity.cs:29,-1	C#
>	0x13 in Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.14-series/88db51a7/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Android.App.Activity.cs:2179,4	C#
>	0x17 in object.6286e64b-04dd-4525-bf1f-df492dd8a816	C#
Comment 1 Udham Singh 2014-06-16 07:55:19 UTC
I have checked this issue with sample project provided in bug description and able to reproduce this issue. Please refer the screencast : http://www.screencast.com/t/qfARNSCM

Output Log : https://gist.github.com/saurabh360/f23272916be21549bfce

Environment Info : 

Widows 8.1
Visual Studio2013
Xamarin 3.1.198.0
Comment 2 T.J. Purtell 2014-06-16 11:21:50 UTC
FYI, this is necessary for anyone trying to add cross-calls from javascript in a webview to C#.  

http://docs.go-mono.com/?link=M%3aAndroid.Webkit.WebView.AddJavascriptInterface(Java.Lang.Object%2c+System.String)
Comment 3 Jonathan Pryor 2014-06-18 11:28:52 UTC
Eno: full stack trace:

> UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: An exception was thrown by the type initializer for Java.Interop.DynamicInvokeTypeInfo ---> System.Reflection.AmbiguousMatchException: Ambiguous matching in method resolution
>   at System.Reflection.Binder.FindMostDerivedMatch (System.Reflection.MethodBase[] match) [0x00000] in <filename unknown>:0 
>   at System.MonoType.GetMethodImpl (System.String name, BindingFlags bindingAttr, System.Reflection.Binder binder, CallingConventions callConvention, System.Type[] types, System.Reflection.ParameterModifier[] modifiers) [0x00000] in <filename unknown>:0 
>   at System.Type.GetMethod (System.String name) [0x00000] in <filename unknown>:0 
>   at Java.Interop.DynamicInvokeTypeInfo..cctor () [0x00000] in <filename unknown>:0 
>   --- End of inner exception stack trace ---
>   at Java.Interop.DynamicCallbackCodeGenerator..ctor (System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0 
>   at Java.Interop.DynamicCallbackCodeGenerator.Create (System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0 
>   at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
>   at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
>   --- End of inner exception stack trace ---
> at System.Reflection.MonoMethod.Invoke (object,System.Reflection.BindingFlags,System.Reflection.Binder,object[],System.Globalization.CultureInfo) <0x00120>
> at System.Reflection.MethodBase.Invoke (object,object[]) <0x00047>
> at Android.Runtime.JNIEnv.CreateDynamicCallback (System.Reflection.MethodInfo) <0x0010f>
> at Android.Runtime.JNIEnv.RegisterJniNatives (intptr,int,intptr,intptr,int) <0x00647>
> at (wrapper managed-to-native) object.wrapper_native_0x4158fde1 (intptr,intptr) <0x0003b>
> at Android.Runtime.JNIEnv.AllocObject (intptr) <0x0005b>
> at Android.Runtime.JNIEnv.AllocObject (System.Type) <0x0002b>
> at Android.Runtime.JNIEnv.StartCreateInstance (System.Type,string,Android.Runtime.JValue[]) <0x0002f>
> at Java.Lang.Object..ctor () <0x00053>
> at App2.MyObject..ctor (int) <0x00017>
> at App2.MainActivity.OnCreate (Android.OS.Bundle) <0x0013f>
> at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) <0x0005b>
> at (wrapper dynamic-method) object.158a8bba-6edb-4685-956b-c80bc92d698c (intptr,intptr,intptr) <0x00043>
Comment 4 Jonathan Pryor 2014-06-18 11:30:25 UTC
Eno: This is a regression: the sample works w/o change on XA 4.12.4-20.
Comment 5 Jonathan Pryor 2014-06-18 17:33:25 UTC
Fixed in monodroid/e48e4956.
Comment 6 Jonathan Pryor 2014-06-18 17:39:45 UTC
Fixed in monodroid-4.14-series/be26998c.
Comment 7 Udham Singh 2014-07-07 09:36:20 UTC
We have checked this issue with sample project provided in bug description. Now this is working fine and we are able to run the application without any error.

Hence closing this issue.

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

Environment Info :

Widows 8.1
Visual Studio 2013
Xamarin 3.3.24.0