Can anyone tell me what's wrong with my IL code here?
IL_0000: nop        
IL_0001: ldarg.1    
IL_0002: isinst     MyXmlWriter
IL_0007: stloc.0    
IL_0008: ldloc.0    
IL_0009: ldarg.2    
IL_000a: ldind.ref  
IL_000b: unbox.any  TestEnum
IL_0010: ldfld      Int64 value__/FastSerializer.TestEnum
IL_0015: callvirt   Void WriteValue(Int64)/System.Xml.XmlWriter
IL_001a: nop        
IL_001b: ret       
I'm going crazy here, since I've written a test app which does the same thing as above, but in C#, and in reflector the IL code from that looks just like my DynamicMethod's IL code above (except my test C# app uses a TestStruct with a public field instead of the private value field on the enum above, but I have skipVisibility set to true)...
I get a NullReferenceException.
My DynamicMethod's signature is:
public delegate void DynamicWrite(IMyXmlWriter writer, ref object value, MyContract contract);
I generate the method like this:
List<Type> parameterTypes = new List<Type> { 
   typeof(DMBuilder), 
   typeof(IDynamicSerializationWriter), 
   typeof(object).MakeByRefType(), 
   typeof(MyContract) 
}; 
DynamicMethod dm = new DynamicMethod(string.Format(
  "Write_{0}", 
  contract.TypeName), 
  typeof(void), 
  parameterTypes.ToArray(), 
  typeof(DMBuilder), 
  true
);
var d = dm.CreateDelegate(typeof(DynamicWrite), this);
d(x,y); 
And I'm definitely not passing in anything null.
Thanks in advance!
 
     
    