有人能告诉我这里的IL代码出了什么问题吗?
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#中,在reflector中的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); 我绝对不会传入任何null。
提前感谢!
发布于 2010-03-13 01:53:53
不得不猜测,我敢打赌您发出了一个静态方法,但在C#代码中使用了一个实例方法。肯定有一个"this“参数(arg.0),但它从未被使用过。将其声明为静态,然后重新编译和反汇编。
发布于 2015-01-08 05:14:41
IL_0002 isinst 此指令在local.0中推送null。您可以将其删除。
https://stackoverflow.com/questions/2434642
复制相似问题