Skip to content

Commit 79eed70

Browse files
committed
[Java.Interop.Export] Remove Action/Func use.
Context: dotnet/android#4631 Context: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=3685184&view=logs&j=b1314ebb-4483-559c-0367-730fc62c4440&t=5022c07e-db44-5ce4-1a38-092215b61c50 Context: 70fc4c0 Commit 70fc4c0 broke use of `jnimarshalmethod-gen.exe` within xamarin-android and `Mono.Android.dll`, as it allows methods taking more than 14 parameters to be bound, which results in `jnimarshalmethod-gen.exe` trying to use an `Action<…>` or `Func<…>` that takes more than 16 parameters, which isn't allowed: EXEC : error : jnimarshalmethod-gen: Unable to process assembly '…/xamarin-android/bin/Release/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v10.0/Mono.Android.dll' An incorrect number of type arguments were specified for the declaration of an Action type. Parameter name: typeArgs System.ArgumentException: An incorrect number of type arguments were specified for the declaration of an Action type. Parameter name: typeArgs at System.Linq.Expressions.Expression.GetActionType (System.Type[] typeArgs) at Java.Interop.MarshalMemberBuilder.CreateMarshalToManagedExpression (System.Reflection.MethodInfo method, Java.Interop.JavaCallableAttribute callable, System.Type type) at Java.Interop.MarshalMemberBuilder.CreateMarshalToManagedExpression (System.Reflection.MethodInfo method) at Xamarin.Android.Tools.JniMarshalMethodGenerator.App.CreateMarshalMethodAssembly (System.String path) at Xamarin.Android.Tools.JniMarshalMethodGenerator.App.ProcessAssemblies (System.Collections.Generic.List`1[T] assemblies) Looks like we don't actually *need* to lookup a delegate type, as there's an `Expression.Lambda()` overload which only requires the lambda body and parameters. Use that instead. Remove use of `Expression.GetActionType()` and `Expression.GetFuncType()`, as these will fail when dealing with methods that contain more than 14 parameters:
1 parent 56955d9 commit 79eed70

1 file changed

Lines changed: 1 addition & 11 deletions

File tree

src/Java.Interop.Export/Java.Interop/MarshalMemberBuilder.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,25 +219,15 @@ public LambdaExpression CreateMarshalToManagedExpression (MethodInfo method, Jav
219219
envpBody.Add (Expression.Label (exit, Expression.Default (jniRType)));
220220
}
221221

222-
var funcTypeParams = new List<Type> ();
223222
var bodyParams = new List<ParameterExpression> ();
224223
if (!direct) {
225-
funcTypeParams.Add (typeof (IntPtr));
226-
funcTypeParams.Add (typeof (IntPtr));
227224
bodyParams.Add (jnienv);
228225
bodyParams.Add (context);
229226
}
230-
foreach (var p in marshalParameters)
231-
funcTypeParams.Add (p.Type);
232-
if (ret != null)
233-
funcTypeParams.Add (ret.Type);
234-
var marshalerType = ret == null
235-
? Expression.GetActionType (funcTypeParams.ToArray ())
236-
: Expression.GetFuncType (funcTypeParams.ToArray ());
237227

238228
bodyParams.AddRange (marshalParameters);
239229
var body = Expression.Block (envpVars, envpBody);
240-
return Expression.Lambda (marshalerType, body, bodyParams);
230+
return Expression.Lambda (body, bodyParams);
241231
}
242232

243233
void CheckMarshalTypesMatch (MethodInfo method, string signature, ParameterInfo[] methodParameters)

0 commit comments

Comments
 (0)