Bugzilla – Bug 320642
[GMCS] Crash invoking generic method using MethodInfo.Invoke
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by adam.lofts@gmail.com 2006-03-23 16:35:20 MST ---- I'm pretty sure this is a mono bug (sorry if its not). Not sure if compiler or runtime. Not sure even if this is valid C#. adam@a3000:~/Desktop$ cat Test.cs using System; using System.Threading; using System.Collections.Generic; using System.Reflection; public class A { public static void Go <T1, T2> (KeyValuePair <T1, T2> kvp) { Console.WriteLine ("Go: Kvp: {0}", kvp); Console.WriteLine ("Go: 1: {0} 2: {1}", kvp.Key, kvp.Value); } public static void Main () { KeyValuePair<string, uint> kvp = new KeyValuePair<string, uint> ("a", 21); Type type = kvp.GetType (); Type [] arguments = type.GetGenericArguments (); MethodInfo method = typeof (A).GetMethod ("Go"); MethodInfo generic_method = method.MakeGenericMethod (arguments); Console.WriteLine ("About to invoke: {0}", method); generic_method.Invoke (null, new object [] { kvp }); } } adam@a3000:~/Desktop$ gmcs Test.cs -out:Test.exe adam@a3000:~/Desktop$ ./Test.exe About to invoke: Void Go[T1,T2](KeyValuePair`2) Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object in <0x0009a> System.Collections.Generic.KeyValuePair`2[System.String,System.UInt32]:ToString () in <0x00340> System.String:FormatHelper (System.Text.StringBuilder result, IFormatProvider provider, System.String format, System.Object[] args) in <0x0004d> System.String:Format (IFormatProvider provider, System.String format, System.Object[] args) in <0x00056> System.String:Format (System.String format, System.Object arg0) in <0x00027> System.IO.TextWriter:Write (System.String format, System.Object arg0) in <0x0002b> System.IO.TextWriter:WriteLine (System.String format, System.Object arg0) in <0x00040> System.IO.SynchronizedWriter:WriteLine (System.String format, System.Object value) in <0x00033> System.Console:WriteLine (System.String format, System.Object arg0)in <0x0003a> A:Go[String,UInt32] (KeyValuePair`2 kvp) in <0x00000> <unknown method> in (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[]) in <0x000da> System.Reflection.MonoMethod:Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)--- End of inner exception stack trace --- in <0x00179> System.Reflection.MonoMethod:Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) in <0x00034> System.Reflection.MethodBase:Invoke (System.Object obj, System.Object[] parameters) in <0x00122> A:Main () adam@a3000:~/Desktop$ mono --version Mono JIT compiler version 1.1.13.4, (C) 2002-2005 Novell, Inc and Contributors. www.mono-project.com TLS: __thread GC: Included Boehm (with typed GC) SIGSEGV : normal adam@a3000:~/Desktop$ gmcs --version Mono C# compiler version 1.1.13.4 ---- Additional Comments From rharinath@novell.com 2006-04-01 14:10:10 MST ---- this appears to be a runtime bug. Instrumenting mono_runtime_invoke_array gives different errors depending on whether printf or fprintf was used -- suggesting there's some memory corruption. ---- Additional Comments From adam.lofts@gmail.com 2006-05-25 13:10:40 MST ---- Any word on this? It's holding up dbus mono bindings. ---- Additional Comments From vargaz@gmail.com 2006-07-01 12:35:10 MST ---- Fixed in SVN. Unknown operating system unknown. Setting to default OS "Other".