[Mono-bugs] [Bug 366400] New: DynamicMethod hits a "implement me" / " should notbe reached" error

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Mar 1 10:37:18 EST 2008


https://bugzilla.novell.com/show_bug.cgi?id=366400


           Summary: DynamicMethod hits a "implement me" / "should notbe
                    reached" error
           Product: Mono: Runtime
           Version: 1.2.6
          Platform: x86
        OS/Version: Windows XP
            Status: NEW
          Severity: Blocker
          Priority: P5 - None
         Component: misc
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: timoch at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Development


Description of Problem:

A program using dynamic methods to map calls to delegates to actual static or
instance methods throws errors when run.

The sample program provided below compiles and runs as expected under ms.net
runtime. However, it does compile but does not run under mono

Steps to reproduce the problem:
1. Compile and run the following program 

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection.Emit;
using System.Reflection;
using System.Globalization;

namespace DynamicMethodTest {
    class Program {
        public delegate object BodyDelegate(object[] parameters);

        public static int GetInt(int i) {
            return i;
        }

        static void Main(string[] args) {
            MethodInfo minfo = typeof(Program).GetMethod("GetInt");
            DynamicMethod method = new DynamicMethod("GetInt", typeof(object),
                new Type[] { typeof(object[]) }, typeof(Program).Module);

            // generate the method body
            ILGenerator generator = method.GetILGenerator();

            MethodInfo changetype = typeof(Convert).GetMethod("ChangeType", new
Type[] { typeof(object), typeof(Type), typeof(IFormatProvider) });
            MethodInfo gettypefromhandle =
typeof(Type).GetMethod("GetTypeFromHandle", new Type[] {
typeof(RuntimeTypeHandle) });
            MethodInfo get_InvariantCulture =
typeof(CultureInfo).GetMethod("get_InvariantCulture", BindingFlags.Static |
BindingFlags.Public,
                null, Type.EmptyTypes, null);
            // for each parameter of the original method, load it on stack
            ParameterInfo[] parameters = minfo.GetParameters();
            for (int i = 0; i < parameters.Length; i++) {
                ParameterInfo par = parameters[i];
                // load the array
                generator.Emit(OpCodes.Ldarg, 0);
                // load the index in the array
                generator.Emit(OpCodes.Ldc_I4, (int)i);
                // get the element at given index
                generator.Emit(OpCodes.Ldelem_Ref);
                // convert it if necessary
                if (par.ParameterType.IsPrimitive || par.ParameterType ==
typeof(string)) {
                    // load the parameter type onto stack
                    generator.Emit(OpCodes.Ldtoken, par.ParameterType);
                    generator.EmitCall(OpCodes.Callvirt, gettypefromhandle,
null);
                    // load the invariant culture onto stack
                    generator.EmitCall(OpCodes.Call, get_InvariantCulture,
null);
                    // call Convert.ChangeType
                    generator.EmitCall(OpCodes.Call, changetype, null);
                    // if necessary, unbox the value
                    if (par.ParameterType.IsValueType)
                        generator.Emit(OpCodes.Unbox_Any, par.ParameterType);
                }
            }

            generator.EmitCall(OpCodes.Call, minfo, null);

            if (minfo.ReturnType == typeof(void))
                generator.Emit(OpCodes.Ldnull);
            if (minfo.ReturnType.IsValueType)
                generator.Emit(OpCodes.Box, minfo.ReturnType);
            generator.Emit(OpCodes.Ret);

            BodyDelegate del =
(BodyDelegate)method.CreateDelegate(typeof(BodyDelegate));
            Console.WriteLine(del(new object[] { 0 }));
        }
    }
}

Actual Results:

When run under MacOSX 10.5 : 
** (Program.exe:8198): WARNING **: mono_class_from_mono_type: implement me 0x00


** ERROR **: file class.c: line 3935 (mono_class_from_mono_type): should not be
reached
aborting...
Stacktrace:

  at (wrapper managed-to-native) System.Type.internal_from_handle (intptr)
<0x00004>
  at (wrapper managed-to-native) System.Type.internal_from_handle (intptr)
<0xffffffff>
  at System.Type.GetTypeFromHandle (System.RuntimeTypeHandle) [0x00000] in
/private/tmp/monobuild/build/BUILD/mono-1.2.6/mcs/class/corlib/System/Type.cs:529
  at (wrapper dynamic-method) System.Object.GetInt (object[]) <0xffffffff>
  at DynamicMethodTest.Program.Main (string[]) <0x00841>
  at (wrapper runtime-invoke)
DynamicMethodTest.Program.runtime_invoke_void_string[]
(object,intptr,intptr,intptr) <0xffffffff>
Abort trap


When run under Windows XP : 
** (Program.exe:3112): WARNING **: mono_class_from_mono_type: implement me 0x00


This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

and a popup windows shows : "** ERROR **: file class.c: line 3935
(mono_class_from_mono_type): should not be reached
aborting..."

Expected Results:

The program should output a single line :
0

How often does this happen? 
Always

Additional Information:
It runs perfectly under ms.net implementation


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list