Bug 45382 - Cannot subclass Java types in a Workbook
Summary: Cannot subclass Java types in a Workbook
Status: CONFIRMED
Alias: None
Product: Workbooks & Inspector
Classification: Xamarin
Component: Actually Unsure ()
Version: master
Hardware: PC Mac OS
: Normal enhancement
Target Milestone: Future
Assignee: xamarininteractive
URL:
Depends on:
Blocks:
 
Reported: 2016-10-13 20:23 UTC by Tom Opgenorth
Modified: 2017-02-27 22:26 UTC (History)
5 users (show)

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


Attachments
Sample workbook that subclasses Android.View.Views (2.94 KB, text/plain)
2016-10-13 20:23 UTC, Tom Opgenorth
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 for Bug 45382 on Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.
Related Links:
Status:
CONFIRMED

Description Tom Opgenorth 2016-10-13 20:23:14 UTC
Created attachment 18031 [details]
Sample workbook that subclasses Android.View.Views

Trying out some Workbooks for the Xamarin portal with an example on 2D drawing by subclassing Android.Views.View. When I try to run the workbook, the following error message is generated:

ClassNotFoundException: Didn't find class "md5fb300bd0009f8e0218a62a61bd003166.ߐ尰00#0-1_MyRedGreenBar" on path: DexPathList[[zip file "/data/app/com.xamarin.workbook_app_android-2/base.apk"],nativeLibraryDirectories=[/data/app/com.xamarin.workbook_app_android-2/lib/x86, /vendor/lib, /system/lib]]
at JniObjectReference Java.Interop.JniEnvironment.Types.FindClass (string classname)
at Java.Interop.JniType..ctor (string classname)
at Java.Interop.JniPeerMembers.JniInstanceMethods..ctor (Type declaringType)
at JniPeerMembers.JniInstanceMethods Java.Interop.JniPeerMembers.JniInstanceMethods.GetConstructorsForType (Type declaringType)
at JniObjectReference Java.Interop.JniPeerMembers.JniInstanceMethods.StartCreateInstance (string constructorSignature, Type declaringType, JniArgumentValue* parameters)
at Android.Views.View..ctor (Context context)
at MyRedGreenBar..ctor (Context context)

Steps to duplicate:

1. Create an Android.View.Views subclass in a workbook (see attached workbook for a sample).
2. Add the view to the activity. When the View runs, the error will occur.

It seems that the problem is with trying to subclass Java types in a Workbook. The APK that the workbook uses doesn't have the ACW for the View subclass (when Workbook packages the APK and starts the app in the emulator the ACW class doesn't exist).

Subclassing Java types (specifically Android types) in Android apps is a very common practice.
Comment 1 Mark McLemore 2016-10-13 20:35:30 UTC
I'm having a similar problem when trying to start another Activity via an Intent (another very common practice in Android):

using Android.App;
using Android.Runtime;
using Android.Content;
using Android.Widget;
using Android.OS;

var rootActivity = StartedActivities.First ();

public class MyActivity: Activity 
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
    }
}

Intent i = new Intent(rootActivity, typeof(MyActivity));
rootActivity.StartActivity(i);


Results in the error:

ClassNotFoundException: Invalid name: md52abe94661ee135a73b2905e1316ec46e.🐵0000#0-2_MyActivity
at void System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
at JniObjectReference Java.Interop.JniEnvironment.StaticMethods.CallStaticObjectMethod (JniObjectReference type, JniMethodInfo method, JniArgumentValue* args)
at IntPtr Android.Runtime.JNIEnv.CallStaticObjectMethod (IntPtr jclass, IntPtr jmethod, JValue* parms)
at IntPtr Android.Runtime.JNIEnv.CallStaticObjectMethod (IntPtr jclass, IntPtr jmethod, JValue[] parms)
at IntPtr Android.Runtime.JNIEnv.FindClass (string classname)
at IntPtr Android.Runtime.JNIEnv.FindClass (Type type)
at void System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
at void System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (Task task)
at void System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (Task task)
at void System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (Task task)
at object System.Runtime.CompilerServices.ConfiguredTaskAwaitable<object>.ConfiguredTaskAwaiter.GetResult ()
at void Xamarin.Interactive.Compilation.CompilationExecutionContext<object>.<RunAsync>d__12.MoveNext ()

Steps to duplicate:

1. Place the above code in a workbook.
2. Run it.
Comment 2 Arpit Jha 2016-10-14 10:43:05 UTC
I have checked this issue with workbooks 0.10.0627 and I am also able to reproduce this issue with the help of bug description and observing same behaviour.

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

XS About: https://gist.github.com/Arpit360/04d079015e02de38cc1a1749f0bdbf87
Comment 3 Sandy Armstrong [MSFT] 2016-10-20 21:22:01 UTC
Correct, you cannot currently subclass Java types in a workbook. We will investigate ways around this in the future.