Replies: 1 comment 4 replies
-
Cecil usually managed this, what it does not manage out of the box is when short form overflow, like you're inserting stuff between a br.s and its target. That's usually fixed by calling helper methods from the .Rocks assembly: method.Body.SimplifyMacros(); // turn short forms into long forms // modify IL method.Body.OptimizeMacros(); // turn long forms into short forms if they fit If that's not the issue you're seeing, please submit a repro. Thank you! |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a build task that, for some methods, will essentially wrap the existing method body in two nested try blocks (it does other things too, but the impact there is smaller).
Sometimes, usually related to the
leave
instruction, this results in invalid IL because branches that I did not touch directly are generated back with the exact target offset they had when reading in the assembly, which is no longer valid due to the nodes inserted at the start of the method, often making them point in the middle of an instruction (luckily I suppose, because then at least I get anInvalidProgramException
, which is better than bad jumps).I was wondering whether that's considered a bug in Cecil, whether there are additional flags/methods I should use to enable this to be handled, or whether I should essentially find all branches in the method body and apply deltas to their offsets myself?
(My latest incident was with a method ending in a
string
-basedswitch
, where most of thebreak
s had been compiled toleave
s (in Release mode at least). All of those broke when adding the try blocks.)If Cecil is supposed to manage this for me, I'll try to make a minimal test case and file an issue; otherwise, any general tips on how best to manage this would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions