Hi Yves, It's hard to say exactly what is going wrong without looking at some code. A few tips:
* If peverify can get pretty obscure, at least it's usually good at finger pointing IL issues. * Make sure you have no peverify error before injecting your code, and compare after. * Prefer using ILDASM over any other tool to have a look at the IL. * Cecil will update the branches target, but will currently not change the kind of opcode, so you can overflow. You can workaround it easily with the Simplify/Optimize Macros extension methods of Mono.Cecil.Rocks. Jb On Sat, Mar 15, 2014 at 12:41 AM, Yves Goergen <[email protected]> wrote: > I've been doing a few changes to an assembly now and one of them is causing > big trouble. I could insert several new instructions throughout all methods > and everything was fine. > > When I replace a ldstr instruction with an ldsfld instruction, it fails in a > few cases (10 out of thousands). I use ILProcessor.Replace, but a > combination of InsertAfter and then Remove also fails with the same verify > errors. > > PEVerify gives me the following types of errors from all over the assembly: > > * jmp / exception in the middle of an instruction > * The stack depth depends on the path > * Stack overflow > > (Rough translations from my localised PEVerify) > > Where do these errors come from? ILSpy fails to show me the IL code for the > first error type. And I cannot see any problem from reading the IL code at > the other errors. Could Cecil generate invalid code here and needs to be > fixed (I'm using 0.9.5 release) or could this well be my fault by putting > instructions in a context where I shouldn't do this? How can I detect such > contexts where not to do anything with instructions? It seems to work > everywhere and Cecil (or whatever) even seems to update all branch and > switch offsets accordingly. At least this has worked in many cases already > and the processed application was still running fine. > > I see my modifications in the IL code all over the place, but only very few > of them cause problems. > > -- > -- > -- > 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. -- -- -- 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.
