Ahhh, I found out, that entries in switch operand array are null, because
enum value is not handled in original code. If I change the code to handle
all enum values and if adding an explicit return, the entries will not be
null anymore.
But I will not change the original code, the injection has to handle this
:-(. Why does relector show an explicit return entry but mono cecil shows
null in this case?
Am Mittwoch, 14. Januar 2015 15:11:18 UTC+1 schrieb Reh Gina:
>
> I have a switch statement which does not handle all enum values. The IL
> code shows
>
> L_0069: switch (L_008f, L_024b, L_019c, L_024b, L_024b, L_01ae, L_0257)
>
>
> L_024b for last return instruction.
>
>
> After injection L_024b does not exist anymore and I tried to replace L_024b
> in switch statement by new leave instruction (encapsulated code by try
> finally block).
>
>
> While looping through values in Operand array of switch instruction all items
> which should contain L_024b are null.
>
>
> I implemented following code to fix this
>
> if (instruction.Operand != null && instruction.OpCode == OpCodes.Switch)
> {
> Instruction[] switchInstructions = instruction.Operand as
> Instruction[];
> for (int i = 0; i < switchInstructions.Length; i++)
> {
> var ins = switchInstructions[i];
> if (ins == null)
> {
> switchInstructions[i] = leaveInstruction;
> }
> }
> }
>
>
>
> But after saving dll to disk and having a look into IL code with .Net
> Reflector the array still contains L_024b which does not exist anymore.
>
>
> Has anybody an idea why replacing this instruction reference does not work?
>
> Does anybody know why values in array are null if looking into them via
> debugger, but are not if looking into IL code via reflector?
>
>
>
>
--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups
"mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.