I'm currently working on a compiler for a language (an external byte-code), and am using System.Reflection.Emit
.
Now, everything looks fine when I open the generated assembly in reflector, and it re-compiles as C# just fine as well (and runs), but when I try to run the main function which gets generated, I get an InvalidProgramException
:
"Common Language Runtime detected an invalid program."
It is probably just a single op-code that is causing the issue, but, because that main function uses 100+ op-codes, I can't determine which op-code is causing the issue.
Each op-code is very involved, so manually testing every op-code is a no-go.
Is there a way to get .NET to tell me where in the function it's detecting an invalid program?
And if not, is there some other tool I can use to determine the source of the issue?