Bug 1321 - Using InvokeMember with namedParameters throws NullReferenceException
Summary: Using InvokeMember with namedParameters throws NullReferenceException
Alias: None
Product: Runtime
Classification: Mono
Component: Reflection ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2011-10-06 15:53 UTC by Nicholas Schell
Modified: 2011-12-22 19:15 UTC (History)
2 users (show)

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

Console App displaying issue (766 bytes, text/x-csharp)
2011-10-06 15:53 UTC, Nicholas Schell

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 GitHub or Developer Community 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:

Description Nicholas Schell 2011-10-06 15:53:58 UTC
Created attachment 630 [details]
Console App displaying issue

Recreate issue:
Create array of arguments with differing types which do not match the method signature.

object[] arr = new object[] { 2, "string" };
//method signature is
public static void testMethod(string a, int b);

Create an array for the parameter names so they can be correctly reordered.
string[] arrStr = new string[] { "b", "a" };

When calling InvokeMember with these (and other typical params, see attached code) a NullReferenceException will be thrown when the Binder is attempting to reorder the parameters.

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
  at System.Reflection.Binder+Default.ReorderParameters (System.String[] names, System.Object[]& args, System.Reflection.MethodBase selected) [0x00016] in /build/buildd/mono-2.10-2.10.5/mcs/class/corlib/System.Reflection/Binder.cs:218 

This problem does not manifest itself under Windows with .NET runtimes. If however you create the arguments in the order following the method signature (and also modify the arrStr) the program will run without a hitch. Changing framework versions has made no difference.

Also this seems to look strangely similar to a bug mentioned on Novell's tracker, which is listed as resolved.

I am running:
Ubuntu 11.04
Mono 2.10.5 (also tried with Mono 2.6.7 from Natty repo's)
MonoDevelop 2.6

Mono 2.10.5 binaries acquired from this ppa: https://launchpad.net/~ermshiperete/+archive/monodevelop

Also tested on Windows XP with the officially distributed Mono 2.10.5 package, and the same exception is thrown (but not with .NET again).
Comment 1 Nicholas Schell 2011-10-06 15:56:50 UTC
Actually meant to post this under CORLIB in Class Libraries, as that may be more relevant concerning the stacktrac mentioning it.
Comment 2 Zoltan Varga 2011-10-08 00:29:46 UTC
Fixed in HEAD by 1c866f28307c43b76ecaa3bbd8d506bddd2a39ae.