M
magounc
I am new to creating dynamic methods and I find that I have need to do
so. I have read through some IL and emit examples and have gotten some
simple programs to work. However, I cannot seem to use the opcode Call
correctly. This example gives me an "CLR detectd and invalid program"
exception at the line handler.invoke. I am sure the error is a simple
one. Could someone help me?
public partial class ILTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DynamicMethod handler = new DynamicMethod("", null, null,
typeof(ILTest).Module);
ILGenerator ilgen = handler.GetILGenerator();
MethodInfo miCall = typeof(ILTest).GetMethod("CallThis");
ilgen.Emit(OpCodes.Call, miCall);
ilgen.Emit(OpCodes.Ret);
handler.Invoke(this, null);
}
public void CallThis()
{
Response.Write("CALLED");
}
}
Thanks,
Chris Magoun
so. I have read through some IL and emit examples and have gotten some
simple programs to work. However, I cannot seem to use the opcode Call
correctly. This example gives me an "CLR detectd and invalid program"
exception at the line handler.invoke. I am sure the error is a simple
one. Could someone help me?
public partial class ILTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DynamicMethod handler = new DynamicMethod("", null, null,
typeof(ILTest).Module);
ILGenerator ilgen = handler.GetILGenerator();
MethodInfo miCall = typeof(ILTest).GetMethod("CallThis");
ilgen.Emit(OpCodes.Call, miCall);
ilgen.Emit(OpCodes.Ret);
handler.Invoke(this, null);
}
public void CallThis()
{
Response.Write("CALLED");
}
}
Thanks,
Chris Magoun