You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 9, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 9, 2026. It is now read-only.
We use the primitive arrays value marshaler, like JavaInt32Array.ValueMarshaler, from marshal methods. These classes are internal and thus not accessible from new generated Jni marshal methods.
Example usage from marshal method generated by jnimarshalmethod-gen.exe:
android.runtime.JavaProxyThrowable: System.MethodAccessException: Method `Java.Interop.JavaInt32Array+ValueMarshaler..ctor()' is inaccessible from method `Xamarin.Forms.Platform.Android.ButtonDrawable+__<$>_jni_marshal_methods.n_onStateChange_[I(intptr,intptr,intptr)'
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_throw_method_access(intptr,intptr)
at Xamarin.Forms.Platform.Android.ButtonDrawable+__<$>_jni_marshal_methods.n_onStateChange_[I (System.IntPtr __jnienv, System.IntPtr __this, System.IntPtr state) [0x00023] in <7999cc4bd5664eca8a72469344172ca3>: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 <18e0da80b61c461b881f5127d588455e>:0
at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0002a] in <18e0da80b61c461b881f5127d588455e>:0
at Android.Views.View.set_Background (Android.Graphics.Drawables.Drawable value) [0x00031] in <6eeeeb44090e4e93a906cc5efec9a894>:0
at Xamarin.Forms.Platform.Android.ViewExtensions.SetBackground (Android.Views.View view, Android.Graphics.Drawables.Drawable drawable) [0x00011] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.ButtonBackgroundTracker.UpdateDrawable () [0x0028b] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.ButtonBackgroundTracker.UpdateBackgroundColor () [0x00000] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer.UpdateBackgroundColor () [0x0001b] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer.UpdateAll () [0x0001e] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1[TElement] e) [0x000ad] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x000dd] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.Platform.CreateRenderer (Xamarin.Forms.VisualElement element, Android.Content.Context context) [0x0001f] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.VisualElementPackager.AddChild (Xamarin.Forms.VisualElement view, Xamarin.Forms.Platform.Android.IVisualElementRenderer oldRenderer, Xamarin.Forms.Platform.Android.RendererPool pool, System.Boolean sameChildren) [0x0009e] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.VisualElementPackager.SetElement (Xamarin.Forms.VisualElement oldElement, Xamarin.Forms.VisualElement newElement) [0x0013a] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.VisualElementPackager.Load () [0x00000] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetPackager (Xamarin.Forms.Platform.Android.VisualElementPackager packager) [0x00007] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x000fa] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.Android.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00027] in <7999cc4bd5664eca8a72469344172ca3>:0
at Xamarin.Forms.Platform.Android.Platform.CreateRender
We should see if JniValueMarshaler<T> and subclasses are thread-safe. (I think they are, but this should be verified.) If they are/can be thread-safe, then we should introduce new public properties which obtain the marshaler:
This will in turn allow removing the new JavaInt32Array.ValueMarshaler() invocation from the marshal method, which will reduce GC pressure.
JniRuntime.JniPrimitiveArrayMarshalers should in turn be updated so that instead of creating new instances from GetValueMarshaler(Type), the already created instance is used instead.
The JniValueMarshaler<T> and subclasses looks OK and should be thread safe. We are already have static instances in the primitive array and GetValueMarshaler(Type) uses them.
The marshaling here goes thru different path than GetValueMarshaler(Type) though. It is prepared in CreateParameterToManagedExpression.
In the above mentioned PR I have overridden that method in the primitive arrays and use newly added method in primitive arrays classes, which uses the static ArrayMarshaler field as well.
With that in place we get further and do not get the System.MethodAccessException anymore. The marshaling is still not complete though as we need to implement Android.Runtime.AndroidValueManager.AddPeer in XA.
Activity
radekdoulik commentedon Sep 20, 2018
Example of the exception we get at runtime:
jonpryor commentedon Sep 21, 2018
We should see if
JniValueMarshaler<T>and subclasses are thread-safe. (I think they are, but this should be verified.) If they are/can be thread-safe, then we should introduce new public properties which obtain the marshaler:This will in turn allow removing the
new JavaInt32Array.ValueMarshaler()invocation from the marshal method, which will reduce GC pressure.JniRuntime.JniPrimitiveArrayMarshalersshould in turn be updated so that instead of creating new instances fromGetValueMarshaler(Type), the already created instance is used instead.[Java.Interop] Fix primitive arrays marshaling
[Java.Interop] Fix primitive arrays marshaling
[Java.Interop] Fix primitive arrays marshaling
radekdoulik commentedon Sep 26, 2018
The
JniValueMarshaler<T>and subclasses looks OK and should be thread safe. We are already have static instances in the primitive array andGetValueMarshaler(Type)uses them.The marshaling here goes thru different path than
GetValueMarshaler(Type)though. It is prepared inCreateParameterToManagedExpression.In the above mentioned PR I have overridden that method in the primitive arrays and use newly added method in primitive arrays classes, which uses the static
ArrayMarshalerfield as well.With that in place we get further and do not get the
System.MethodAccessExceptionanymore. The marshaling is still not complete though as we need to implementAndroid.Runtime.AndroidValueManager.AddPeerin XA.[Java.Interop] Optimize primitive array marshaling (#377)
Bump to xamarin/Java.Interop/master@8ee34a35
Bump to xamarin/Java.Interop/master@8ee34a35 (#2286)
[Java.Interop] Optimize primitive array marshaling (#377)