任何人都可以告诉我这里的IL代码有什么问题吗?DynamicMethod NullReferenceException
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
我快要疯了这里,因为我写了一个测试应用程序,它确实与上述同样的事情,但在C#中,并在反射器从IL代码看起来就像是我的DynamicMethod的的IL代码上方(除了我的测试C#应用程序使用公共字段的TestStruct而不是上面枚举的私有值字段,但我的skipVisibility设置为true)...
我得到一个NullReferenceException。
我DynamicMethod的签名是:
public delegate void DynamicWrite(IMyXmlWriter writer, ref object value, MyContract contract);
我生成这样的方法:
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);
而且我绝对不会传递任何空。
在此先感谢!
可能重复[什么是NullReferenceException,我该如何解决它?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-doi-i-fix-它) – Nasreddine