[Mono-dev] Re: emitting a MethodInfo instance

Valient Gough valient at gmail.com
Fri Aug 12 11:37:38 EDT 2005

Adding a followup for list-archive completeness. 

On 5/31/05, Valient Gough <valient at gmail.com> wrote:

> Forgot to add, my first guess was actually to use OpCode.Ldtoken to
> directly load MethodInfo

> However, when I try and emit (OpCode.Ldtoken, MethodInfo), that causes
> the ILGenerator to halt in mid-opcode, and monodis shows that last
> opcode as "ldtoken" with no args..  Perhaps ILGenerator.Emit(OpCode,
> MethodInfo) only works in mono 1.1.7 where OpCode == OpCode.Call* ?

Mono is able to emit the code, but monodis can't seem to decompile it.
Ref bug #75544: http://bugzilla.ximian.com/show_bug.cgi?id=75544

The following code will emit a MethodInfo reference into IL code, and
the code will work fine, but it will render the resulting .dll
undecodable by monodis:

void Emit_MethodInfo(ILGenerator ig, MethodInfo method)
    ig.Emit( OpCodes.Ldtoken, method ); // this crashes monodis
    ig.Emit( OpCodes.Call, 
    ig.Emit( OpCodes.Castclass, typeof(MethodInfo) );

More information about the Mono-devel-list mailing list