   [.net] Call internal Method on a structure
  Hi!I'm trying to call an internal method in a structure - but without generating any garbage. The internal method modifies the structure, so I want to avoid copying the structure around.The problem is that I've got zero experience with MSIL and never used IlGenerator.Emit() before. This is what the method I'm trying to call looks like:public enum TouchLocationState { Pressed, Moved, Released };public struct TouchCollection {  internal void AddTouchLocation(int id, TouchLocationState state);}and this is my attempt at calling it:private delegate void DynamicMethodDelegate(  ref TouchCollection touchCollection,  int id, TouchLocationState state);void test() {  Type byrefTouchCollection = typeof(TouchCollection).MakeByRefType();  var dynamicMethod = new DynamicMethod(    "AddTouchLocation", null,    new Type[] { byrefTouchCollection, typeof(int), typeof(TouchLocationState)    }  );  MethodInfo addTouchLocationMethod = typeof(TouchCollection).GetMethod(    "AddTouchLocation", BindingFlags.Instance | BindingFlags.NonPublic  );  ILGenerator ilGenerator = dynamicMethod.GetILGenerator();  ilGenerator.Emit(OpCodes.Ldarg_1); // thisptr  ilGenerator.Emit(OpCodes.Ldarg_2); // id  ilGenerator.Emit(OpCodes.Ldarg_3); // state  ilGenerator.EmitCall(OpCodes.Call, addTouchLocationMethod, null);  ilGenerator.Emit(OpCodes.Ret);  DynamicMethodDelegate addTouchLocationDelegate =  (DynamicMethodDelegate)dynamicMethod.CreateDelegate(    typeof(DynamicMethodDelegate)  );}The result is a VerificationException with the message "Operation could destabilize the runtime."I think it's most likely that I did something wrong with the this pointer (which I passed by reference so the structure isn't copied). I'm not even sure how the OpCodes.Call gets the this pointer (I came up with this code by looking at a plain method call in reflector).Can anyone fix my probably stupid mistake? ;)   
  I have never tried to use IL to call methods on structs, it is easy for reference types, but things get a little weird when you start working with non-primitive value types.  There is some interesting discussion here (stackoverflow) that might help you, the second answer looks pretty relevant.   ;  For instance methods, "this" is loaded via ldarg_0, not ldarg_1.I think the method AddTouchLocation should be static and accepting an explicit ref param - forcing a "this" byref into an instance method feels like looking for troubles. I also seem to recall that unbound delegates should perform faster than their instance counterparts, but it's totally speculative.