Any method with a local variable crashes
toptensoftware opened this issue · 3 comments
toptensoftware commented
Adding a reference to the rewritten dll from pull request #43 and calling the IntMethod() crashes with System.InvalidProgramException: Common Language Runtime detected an invalid program
.
var x = new MyClass();
x.IntMethod();
Looking at the ildasm listing shows the locals haven't been defined. Here's the original (note the .locals
line)
.method public hidebysig instance int32
IntMethod() cil managed
{
// Code size 7 (0x7)
.maxstack 1
.locals init (int32 V_0)
IL_0000: nop
IL_0001: ldc.i4.0
IL_0002: stloc.0
IL_0003: br.s IL_0005
IL_0005: ldloc.0
IL_0006: ret
} // end of method MyClass::IntMethod
here's the rewritten version: (no .locals
)
.method public hidebysig instance int32
IntMethod() cil managed
{
// Code size 7 (0x7)
.maxstack 8
IL_0000: nop
IL_0001: ldc.i4.0
IL_0002: stloc.0
IL_0003: br.s IL_0005
IL_0005: ldloc.0
IL_0006: ret
} // end of method MyClass::IntMethod
Also, .maxstack is different and wondering if this is just a default and if there might be issues if the function needs more than 8??
toptensoftware commented
I'm guessing this line is the reason for this:
ILPack/src/IL/MethodBodyStreamWriter.cs
Line 32 in ac3c94a
toptensoftware commented
Pull request #48 fixes this.
vermorel commented
Confirmed with Ildasm as well!