[Mono-bugs] [Bug 29036][Nor] New - System.RuntimeMethodHandle (non-)implementation and MS.NET behavior

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
16 Aug 2002 01:31:14 -0000


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by nick@chemlab.org.

http://bugzilla.ximian.com/show_bug.cgi?id=29036

--- shadow/29036	Thu Aug 15 21:31:14 2002
+++ shadow/29036.tmp.19569	Thu Aug 15 21:31:14 2002
@@ -0,0 +1,84 @@
+Bug#: 29036
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: GNU/Linux
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: nick@chemlab.org               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: System.RuntimeMethodHandle (non-)implementation and MS.NET behavior
+
+Description of Problem:
+
+RuntimeMethodHandle.GetFunctionPointer() is not implemented.
+
+RuntimeMethodHandle on MS.NET has some oddities that I don't fully
+understand, but Mono developers probably will. RuntimeMethodHandle.Value
+and RuntimeMethodHandle.GetFunctionPointer() return slightly different
+IntPtr values on Microsoft.NET. On my Win2k system, .Value is always the
+value of .GetFunctionPointer(), plus 5.
+
+Casual browsing of the ECMA spec suggests that the .GetFunctionPointer()
+IntPtr could be refering to the metadata before the method, while .Value
+refers to the method itself. (Partition II, section 24.4)
+
+The MS class reference says that .Value is 'the value of this instance',
+and .GetFunctionPointer() is 'a pointer to the method represented by this
+instance'. This seems a bit ambiguous to me given that they return two
+different IntPtr values.
+
+Steps to reproduce the problem:
+
+Compile and run the following code on Microsoft.NET.
+
+-- BEGIN --
+using System;
+using System.Reflection;
+
+public class Foobar {
+	public static void Main() {
+		MethodInfo info = typeof(Foobar).GetMethod("foo");	
+		RuntimeMethodHandle handle = info.MethodHandle;
+		Console.WriteLine("Value: " + handle.Value);
+		Console.WriteLine("Pointer: " + handle.GetFunctionPointer());
+	}
+
+	public void foo() {
+		Console.WriteLine("Some foobar");
+	}
+}
+-- END --
+
+Actual Program Output:
+
+Value: 3625088
+Pointer: 3625083
+
+Expected Program Output:
+
+Unknown.
+
+How often does this happen? 
+
+Always.
+
+Additional Information:
+
+A bit why this matters to me...
+
+I'm using RuntimeMethodHandle in code I wrote on MS.NET that emits new
+Delegate types at runtime. A Delegate constructor takes an object and the
+address of the method to call on the object. I'm passing the IntPtr to the
+target method as the second parameter of the constructor. When I pass the
+IntPtr obtained via RuntimeMethodHandle.Value, I get a 'Fatal execution
+engine error'. When I use the IntPtr obtained via
+RuntimeMethodHandle.GetFunctionPointer(), the delegated method is invoked
+successfully.