1

I generate assemblies dynamically and invoke methods from those assemblies. I use both visual studio and mono. Sometimes, I do something wrong with ILGenerator.Emit, and get an InvalidProgramException when trying to invoke a method.

Is there any way to get the faulty instruction?

So far I have to disassemble the assembly with ILSpy and manually go through the IL which is OK when the generated method is simple.

Unfortunately, sometimes the generated method contains hundreds of MSIL instructions, and it gets harder to indentify the error.

I wonder if there is anything built-in somewhere to help me.

Unfortunately peverify is not very helpful as I generate unsafe code (with pointers). I therefore get this kind of errors:

Unmanaged pointers are not a verifiable type

In addition, some of those errors only happen with mono, and not within visual studio.

Thanks

Regis Portalez
  • 4,675
  • 1
  • 29
  • 41
  • Can you not use the overall application catch for unhandled events, and the use the stack to tell you what went wrong? – BugFinder Jul 12 '16 at 13:50
  • 1
    Use the [peverify.exe utility](https://msdn.microsoft.com/en-us/library/62bwd2yd(v=vs.110).aspx) to get a better diagnostic. – Hans Passant Jul 12 '16 at 14:01
  • peverify supports `/ignore` switch to ignore specified kinds of errors. Would that help you? – svick Jul 16 '16 at 15:18

0 Answers0