MSDN - InvalidProgramException
Excerpts:
The exception that is thrown when a program contains invalid Microsoft intermediate language (MSIL) or metadata. Generally this indicates a bug in the compiler that generated the program.
This happens when passing through the code, because since your method is called, it is compiled by JIT. If the JITer compilation is invalid, this exception will be thrown at this point.
source share