[Mono-list] mcs bug and Reflection.Emit shortcoming

Jeroen Frijters mono@jeroen.nu
Thu, 13 Jun 2002 17:15:53 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_02AB_01C212FD.F9374510
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

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: mono-list-admin@ximian.com 
> [mailto:mono-list-admin@ximian.com] On Behalf Of Paolo Molaro
> Sent: Thursday, June 13, 2002 16:33
> To: mono-list@ximian.com
> 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
> 
> -- 
> -----------------------------------------------------------------
> lupus@debian.org                                     debian/rules
> lupus@ximian.com                             Monkeys do it better
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
> 

------=_NextPart_000_02AB_01C212FD.F9374510
Content-Type: text/plain;
	name="test.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="test.cs"

using System;
using System.Reflection;
using System.Reflection.Emit;

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

------=_NextPart_000_02AB_01C212FD.F9374510--