Stack Exchange
How do I app.Invoke backdoor method with multiple parameters? At runtime I'm getting System.Exception: "No such method found"
Xamarin.Forms, android project, inside MainActivity:
[Java.Interop.Export("BackDoorMethod")]
private void BackDoorMethod(int param1, int param2, int param3)
{
    // some code here
}

Code to call that method from Xamarin.Uitest project:
app.Invoke("BackDoorMethod", new object[] { 30, 50, 15 }); // causes exception at runtime

Here is StackTrace:
System.Exception: Error while performing Invoke("BackDoorMethod", [ 30, 50, 15 ]) ---> System.Exception: Invoke for BackDoorMethod failed with outcome: ERROR
No such method found: BackDoorMethod([Integer], [Integer], [Integer])
  at Xamarin.UITest.Android.AndroidGestures.Invoke (System.String methodName, System.Object[] arguments) [0x0008d] in <a0c3f09cbf9049cbb8d3a680a53dcf46>:0
  at Xamarin.UITest.Android.AndroidApp+<>c__DisplayClass89_0.<Invoke>b__0 () [0x00000] in <a0c3f09cbf9049cbb8d3a680a53dcf46>:0
  at Xamarin.UITest.Utils.ErrorReporting.With[T] (System.Func`1[TResult] func, System.Object[] args, System.String memberName) [0x0000e] in <a0c3f09cbf9049cbb8d3a680a53dcf46>:0
  --- End of inner exception stack trace ---
  at Xamarin.UITest.Utils.ErrorReporting.With[T] (System.Func`1[TResult] func, System.Object[] args, System.String memberName) [0x0005b] in <a0c3f09cbf9049cbb8d3a680a53dcf46>:0
  at Xamarin.UITest.Android.AndroidApp.Invoke (System.String methodName, System.Object[] arguments) [0x0001b] in <a0c3f09cbf9049cbb8d3a680a53dcf46>:0
  at ProjectName.PageTests.TestClass.TestMethod (System.Int32 param1) [0x00037] in /Users/UserName/Projects/SolutionName/Tests/ProjectName.PageTests.TestClass.cs:124

Attempt to do data type casting like app.Invoke( ... (object)30, (object)50, ... doesn't change anything.
Changing method declaration from 3 parameters of type int to 3 parameters of type object or single parameter of type object[] give compilation error.
Some research led me to info about that Java has data type int, which is value type and Integer, which is reference type, which probably might be the reason for this problem, but C# shouldn't have any problems converting Int32 to object and vice versa. So how can I make it work properly?
P.S. Same approach with single parameter of type int works perfectly.


On Android, IApp.Invoke can be used to invoke a method in the Xamarin.Android application according to the following rules:

The method must be public.

...

(From the documentation, emphasis mine)
Your method is declared as a private method. Should work after making it public.

@ConstantineKetskalo Glad I could help ;)
