A simple test is attached. If you run it and disassemble foo.exe, you'll
see it calls System.Object::ToString instead of testdll::ToString.

BTW, it uses testdll.dll from the previous testcase.

Regards,
Jeroen

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED]] On Behalf Of Paolo Molaro
> Sent: Thursday, June 13, 2002 16:33
> To: [EMAIL PROTECTED]
> Subject: Re: [Mono-list] mcs bug and Reflection.Emit shortcoming
> 
> 
> On 06/13/02 Jeroen Frijters wrote:
> > I just wrote some test code on Microsoft's implementation, and their
> > implementation for Reflection.Emit doesn't use 
> MethodInfo.ReflectedType,
> > so if you change the behaviour of Mono's Reflection.Emit, 
> you won't be
> > compatible.
> 
> Uhm, bummer. Well, I guess that should be reported to the 
> microsoft folks.
> Could you share the tests with us, so I'll make our code do 
> the correct
> thing.
> 
> > I fear that this, along with the (bigger) issue of lack of module
> > support pretty much mean that mcs won't run on Microsoft's
> > implementation. Are there any other issues you're aware of?
> 
> There are a couple of other limitations with the Reflection API:
> you can't know if a field or variable is volatile and you can't add
> required or optional modifiers to types. There may be some more issues
> related to the compilation of corlib.
> mcs already works around a couple of bugs in the ms reflection code
> and issues a warning in that case.
> We plan to workaround any such issues in our corlib until 
> they fix their
> stuff and issue a warning when running with their runtime. Fortunately
> the issues are fairly minor and running mcs with the mono runtime is
> faster anyway:-)
> 
> lupus
> 
> -- 
> -----------------------------------------------------------------
> [EMAIL PROTECTED]                                     debian/rules
> [EMAIL PROTECTED]                             Monkeys do it better
> 
> _______________________________________________
> Mono-list maillist  -  [EMAIL PROTECTED]
> http://lists.ximian.com/mailman/listinfo/mono-list
> 
using System;
using System.Reflection;
using System.Reflection.Emit;

public class Test
{
        public static void Main(string[] args) 
        {
                MethodInfo m = typeof(testdll).GetMethod("ToString");
                Console.WriteLine(m.ReflectedType);
                AssemblyName name = new AssemblyName();
                name.Name = "MyAssembly";
                AssemblyBuilder assemblyBuilder = 
AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Save);
                ModuleBuilder mod = assemblyBuilder.DefineDynamicModule("MyModule", 
"foo.exe");
                TypeBuilder b = mod.DefineType("MyType", TypeAttributes.Class | 
TypeAttributes.Public, typeof(testdll));
                MethodBuilder mb = b.DefineMethod("ToString", MethodAttributes.Virtual 
| MethodAttributes.Public, typeof(string), Type.EmptyTypes);
                ILGenerator ilgen = mb.GetILGenerator();
                ilgen.Emit(OpCodes.Ldarg_0);
                ilgen.Emit(OpCodes.Call, m);
                ilgen.Emit(OpCodes.Ret);
                MethodBuilder main = b.DefineMethod("main", MethodAttributes.Static | 
MethodAttributes.Public, typeof(void), Type.EmptyTypes);
                ilgen = main.GetILGenerator();
                ilgen.Emit(OpCodes.Newobj, 
typeof(Test).GetConstructor(Type.EmptyTypes));
                ilgen.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new 
Type[] { typeof(object) }));
                ilgen.Emit(OpCodes.Ret);
                b.CreateType();
                assemblyBuilder.SetEntryPoint(main, PEFileKinds.ConsoleApplication);
                assemblyBuilder.Save("foo.exe");
        }
}

Reply via email to