I’ve modified the bytecode of an assembly to get rid off of an error and now when I try to use it I get a InvalidProgramException.
All I’ve done is replace this code with NOPS:
catch (Exception exception1)
{
Exception exception = exception1;
if (exception as InvalidValueException == null)
{
throw new InvalidGenerationException(2);
}
else
{
throw exception;
}
}
IL before:
catch [mscorlib]System.Exception
{
IL_022f: stloc.s exception
IL_0231: ldloc.s exception
IL_0233: isinst Custom.InvalidValueException
IL_0238: brfalse.s IL_023d
IL_023a: ldloc.s exception
IL_023c: throw
IL_023d: ldc.i4.1
IL_023e: newobj instance void Custom.InvalidGenerationException ...
IL_0243: throw
}
IL after:
catch [mscorlib]System.Exception
{
IL_022f: nop
IL_0230: nop
IL_0231: nop
IL_0232: nop
IL_0233: nop
IL_0234: nop
IL_0235: nop
IL_0236: nop
IL_0237: nop
IL_0238: nop
IL_0239: nop
IL_023a: nop
IL_023b: nop
IL_023c: nop
IL_023d: nop
IL_023e: nop
IL_023f: nop
IL_0240: nop
IL_0241: nop
IL_0242: nop
IL_0243: nop
}
Any ideas about why is this wrong?
Thanks!
Your original
catchblock will always throw. That is, there’s no way to exit the block “normally”.Your modified
catchblock doesn’t throw so you need to exit the block normally. You’ll need to useleaveorleave.sto do that.(You might also need to
popthe caught exception off the stack to keep things tidy. I’m not sure about that one though, you’ll have to try it and see for yourself.)