[Mono-bugs] [Bug 26204] New - Problem when finding an inherited method
13 Jun 2002 10:40: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 email@example.com.
--- shadow/26204 Thu Jun 13 06:40:14 2002
+++ shadow/26204.tmp.6611 Thu Jun 13 06:40:14 2002
@@ -0,0 +1,71 @@
+Summary: Problem when finding an inherited method
+This bug was posted by Jeroen Frijters" <firstname.lastname@example.org> on mono-list.
+If you compile the attached files, like this:
+mcs --target library testdll.cs
+mcs -r testdll.dll usedll.cs
+And then disassemble usedll.exe, you'll see that ToString calls
+[mscorlib]System.Object::ToString() instead of
+[testdll]testdll::ToString() (as csc does). This will cause version
+problems, if a new version of the dll overrides ToString, it will not be
+The problem is that, AFAIK, Reflection.Emit doesn't have the ability to
+create a MethodInfo for an inherited method, but I hope I'm wrong.
+== cut testdll.cs
+public class testdll
+== cut usedll.cs
+class test : testdll
+ public static void Main()
+ System.Console.WriteLine("hello from test: " + new test());
+ public override string ToString()
+ return "it's me: " + base.ToString();
+Interesting bug. I added support in the runtime to execute code like
+that (that reference methods in an inherited class instead of in the
+declaring class), but I didn't understand why one would produce such code
+and how until your sample test. I even asked about the issue on the
+DOTNET list but no one replied. Thanks!
+The Reflection API provides support for such cases in this way: if you
+call FindMembers() for the ToString() method starting from the testdll
+type (the base type for type test), you'll get a MethodInfo that has:
+ DeclaringType: System.Object
+ ReflectedType: testdll
+So the info is there in the first place. My guess is that mcs sets the
+DeclaredOnly binding flag and loops until it finds the method, so
+ReflectedType is always equal to the DeclaringType. After mcs is fixed
+I'll change our Reflection.Emit code to take into account the
+ReflectedType when emitting the memberref token.