This repository was archived by the owner on Aug 27, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
ProxyValueMarshaler:CreateGenericValue with IJavaObject based types #388
Copy link
Copy link
Closed
Description
Currently the ProxyValueMarshaler doesn't work with types, which don't have own value marshaler and are not based on IPeerable
Example generated marshaler with this problem:
using Android.Widget;
using Java.Interop;
using System;
public static void n_setAdapter_Landroid_widget_ListAdapter_ (IntPtr __jnienv, IntPtr __this, IntPtr value)
{
JniTransition jniTransition = new JniTransition (__jnienv);
JniRuntime runtime = default(JniRuntime);
try {
runtime = JniEnvironment.Runtime;
JniRuntime.JniValueManager valueManager = runtime.ValueManager;
valueManager.WaitForGCBridgeProcessing ();
CanOverrideAbsListView_Adapter value2 = valueManager.GetValue<CanOverrideAbsListView_Adapter> (__this);
Java.Interop.ProxyValueMarshaler proxyValueMarshaler = new Java.Interop.ProxyValueMarshaler ();
value2.Adapter = (IListAdapter)((JniValueMarshaler)proxyValueMarshaler).CreateValue (value, typeof(IListAdapter));
} catch (Exception ex) when (runtime.ExceptionShouldTransitionToJni (ex)) {
jniTransition.SetPendingException (ex);
} finally {
jniTransition.Dispose ();
}
}
The IListAdapter is based on IJavaObject and thus we get this exception during runtime:
Parameter name: targetType
at Java.Interop.JniRuntime+JniValueManager.CreatePeer (Java.Interop.JniObjectReference& reference, Java.Interop.JniObjectReferenceOptions transfer, System.Type targetType) [0x0005e] in <5bb074f8b081416ebee7366fccd97c3a>:0
at Java.Interop.ProxyValueMarshaler.CreateGenericValue (Java.Interop.JniObjectReference& reference, Java.Interop.JniObjectReferenceOptions options, System.Type targetType) [0x00080] in <5bb074f8b081416ebee7366fccd97c3a>:0
at Java.Interop.JniValueMarshaler`1[T].CreateValue (Java.Interop.JniObjectReference& reference, Java.Interop.JniObjectReferenceOptions options, System.Type targetType) [0x00000] in <5bb074f8b081416ebee7366fccd97c3a>:0
at Java.Interop.JniValueMarshaler.CreateValue (System.IntPtr handle, System.Type targetType) [0x00009] in <5bb074f8b081416ebee7366fccd97c3a>:0
at Android.WidgetTests.CanOverrideAbsListView_Adapter+__<$>_jni_marshal_methods.n_setAdapter_Landroid_widget_ListAdapter_ (System.IntPtr __jnienv, System.IntPtr __this, System.IntPtr value) [0x00029] in <712141aca1124903a2d657de1152ceb2>:0
--- End of stack trace from previous location where exception was thrown ---
at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069] in <5bb074f8b081416ebee7366fccd97c3a>:0
at Android.Runtime.JNIEnv.CallVoidMethod (System.IntPtr jobject, System.IntPtr jmethod, Android.Runtime.JValue* parms) [0x0000e] in <e7571f5d9c6a481c97cf71c12b5abd15>:0
at Android.Runtime.JNIEnv.CallVoidMethod (System.IntPtr jobject, System.IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00018] in <e7571f5d9c6a481c97cf71c12b5abd15>:0
at Android.WidgetTests.AdapterTests.InvokeOverriddenAbsListView_AdapterProperty () [0x000c0] in <712141aca1124903a2d657de1152ceb2>: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, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0003b] in <00a49bfe374544b389f2858242e41c55>:0
I think I will try to add value marshaler for IJavaObject based types to the XA. That would help with this common case. Not yet sure what to do about other cases, where we can end up here: https://github.com/xamarin/java.interop/blob/14711837ad7a4c497ec93c772d9bbdcabca8524e/src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs#L698-L699
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
radekdoulik commentedon Oct 25, 2018
So I will override
JniValueManager:GetValueMarshalerCore (Type type)in XA'sAndroidValueManagerand return instance of a newIJavaObjectValueMarshaler, which will take care aboutIJavaObjectbased objects, which are not based onIJavaPeerable.radekdoulik commentedon Oct 26, 2018
That would actually not work as the
jnimarshalmethod-gen.exewill not be usingAndroid.Runtime.AndroidValueManager.I will instead modify the
JniValueManagerto lookup for custom marshaler on implemented interfaces of the type.[Java.Interop] Additional marshaler lookup
[Mono.Android] Add IJavaObject custom marshaler
[Java.Interop] Additional marshaler lookup (#389)
[Mono.Android] Add IJavaObject custom marshaler
radekdoulik commentedon Nov 1, 2018
Fixed in dotnet/android#2153