Dynamic Method's Body and IL ???

  • Thread starter Thread starter VivekR
  • Start date Start date
V

VivekR

Hi

I am using C# 2.0. I need to use the MethodBuilder.CreateMethodBody
that takes byte[] as the input parameter taking the IL codes as byte
array. I feed this input from MethodBody.GetILAsByteArray. But when the
method created dynamically via MethodBuilder.CreateMethodBody is
invoked by TypeBuilder.Invoke, it throws exception [inner exception]
"Bad Method Token". If the body of the method [which is requested as
IL by the MethodBody.GetILAsByteArray] is empty, then the method
executes successfully.

Is there any special that has to be done with the byte [] from
MethodBody.GetILAsByteArray before giving it as input to the
MethodBuilder.CreateBody.

I could not find enough information even on the MSDN documentation
about this.

Your help is appreciated.

Thanks
Vivek Ragunathan
 
Hi,
Are you using right opcodes in the byte[] array? Example 0x02 is
the opcode for ldarg.0.
Naveen
 
I am not using the opcodes by my own. The GetILAsByteArray gives me the
IL as byte array, and i am using that in CreateMethodBody.

Thanks
 
Back
Top