Bug 16698 - Method overload for GetRuntimeMethod() missing from System.Reflection.RuntimeReflectionExtensions
Summary: Method overload for GetRuntimeMethod() missing from System.Reflection.Runtime...
Status: RESOLVED DUPLICATE of bug 15008
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: 7.0.0.x
Hardware: Macintosh Mac OS
: --- enhancement
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2013-12-10 12:21 UTC by Jon Goldberger [MSFT]
Modified: 2013-12-11 17:06 UTC (History)
4 users (show)

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

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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Comment 1 Jon Goldberger [MSFT] 2013-12-10 12:22:00 UTC
Hello Xamarin team,

I just stumbled across this error:

stderr: error MT2002: Failed to resolve "System.Linq.Expressions.MethodCallExpression System.Linq.Expressions.Expression::Call(System.Reflection.MethodInfo,System.Linq.Expressions.Expression)" reference from "System.Linq.Expressions, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

This error comes from this call in our code:

Expression.Call(typeof (char).GetRuntimeMethod("ToUpper", new[] {typeof (char)}), conditionEx));

This code is called within a PCL from Xamarin.iOS 7.0.4. The call works fine in the simulator but linking fails with the above message when deploying to the device.

If I change the code to

Expression.Call(typeof (char).GetRuntimeMethod("ToUpper", new[] {typeof (char)}), new Expression[] { conditionEx }));

(a different overload) it works fine on the device.
Comment 2 Jon Goldberger [MSFT] 2013-12-10 13:35:26 UTC
I think I misread the method call. The missing method is the overload Call(MethodInfo, IEnumerable<Expression>) in System.Linq.Expressions.Expression.
Comment 3 Marek Safar 2013-12-10 14:38:22 UTC
I think that's feature. You are using reflection to call a method which linker does not know about.
Comment 4 Sebastien Pouliot 2013-12-10 14:53:38 UTC
There's a potential issue (linker-wise) if `Char.ToUpper` is not already preserved by something else in the application.

However that's not the problem because:

1. that's a build time error. Linker/reflection issues are seen at runtime (not build time);

2. the 2nd overload works, we can assume `Char.ToUpper` is part of the application (and that's not surprising since it's used in many places inside the BCL itself - making it unlikely to ever be linked out);

3. the error is explicit about what's missing:


not `Char.ToUpper`.

and the above occurs because System.Core, as shipped by Xamarin.iOS, currently only ships:

   public static MethodCallExpression Call (MethodInfo method, params Expression[] arguments)

^ note the `params` and not the newer overloads that .NET has, e.g. the 'params`-less version [1].

[1] http://msdn.microsoft.com/en-us/library/dd323927(v=vs.110).aspx

*** This bug has been marked as a duplicate of bug 15008 ***
Comment 5 Kerry 2013-12-11 17:06:37 UTC
The tricky part is that this problem only occurs when using a PCL. If you compile the above code with a non-PCL project the compiler will just use the params overload since it doesn't know about the other overloads.