.net - Why Does MethodBody.GetILAsByteArray Return Different Arrays on Different Platforms? -
i'm considering instance method object.equals(object). using reflection, posible il method byte array, follows:
var mi = typeof(object).getmethod("equals", bindingflags.instance | bindingflags.public); var mb = mi.getmethodbody(); var bytes = mb.getilasbytearray();
i have 2 pcs: 1 32-bit machine running windows xp, other 64-bit windows 7. both machines have version 4.0.30319 sp1rel of .net framework installed.
on x86 machine, resulting array is:
[0]: 2 [1]: 3 [2]: 40 [3]: 122 [4]: 67 [5]: 0 [6]: 6 [7]: 42
on x64 machine, though, this:
[0]: 2 [1]: 3 [2]: 40 [3]: 123 [4]: 67 [5]: 0 [6]: 6 [7]: 42
the 4th byte different.
now know mscorlib comes in 2 flavours on 64-bit platforms. however, ildasm reveals il method identical between flavours , between machines. on x64 machine have targeted above code @ both "any cpu" , "x86" result same.
so question is, can business relationship noted discrepancy between 2 machines?
update
here's c# , il object.equals(object):
public virtual bool equals(object obj) { homecoming runtimehelpers.equals(this, obj); } .maxstack 8 il_0000: ldarg.0 il_0001: ldarg.1 il_0002: phone call bool system.runtime.compilerservices.runtimehelpers::equals(object, object) il_0007: ret
get improve insight in il content writing method self , looking @ ildasm.exe. utilize view + show bytes in ildasm see byte values, note in hex:
.method public hidebysig newslot virtual instance bool equals(object obj) cil managed // sig: 20 01 02 1c { // method begins @ rva 0x2052 // code size 8 (0x8) .maxstack 8 il_0000: /* 02 | */ ldarg.0 il_0001: /* 03 | */ ldarg.1 il_0002: /* 28 | (0a)000010 */ phone call bool [mscorlib]system.runtime.compilerservices.runtimehelpers::equals(object, object) il_0007: /* 2a | */ ret } // end of method program::equals
you'll see byte @ il_0003 part of method token, to the lowest degree important byte of it. , note how value got drastically different 1 got. because wrote little programme little code test it, has little manifest. disassembler beingness helpful, instead of displaying token value did lookup in metadata table , replaced token method name.
a token index in assembly manifest's metadata tables. such index change when code in assembly changes , requires add-on tables. can read more in cli spec, ecma 335.
.net reflection cil il mscorlib
No comments:
Post a Comment