ANTS Performance Profiler 9

'Common language runtime detected an invalid program' error when profiling

When profiling with line-level timings, the application being profiled may crash with the error message:

Common language runtime detected an invalid program.

We know this happens with applications that use try{} blocks inside the constructor of a generic class, but there may be other patterns that cause the error too. (If your code does not use try, using, lock or foreach statements in a generic constructor, please help us investigate the problem by sending a sample reproduction to


We are still investigating the cause, but it seems related to some security hotfixes included in Windows Update in January 2013.

For more information about these hotfixes, see

How to fix

The best way to work around this problem is to turn off line-level timings. If you need to use line-level timings, you can change your code by extracting the try block into a new method, called by the constructor.

If neither of these options is practical, some customers have worked around this problem successfully by uninstalling KB2742596 (.NET 2.0 on Windows XP / Server 2003) or KB2742599 (.NET 3.5.1 on Windows 7 / Server 2008). On other framework versions or operating systems, you may need to uninstall other hotfixes from Microsoft Security Bulletin MS13-004.

Uninstalling these security hotfixes may leave your computer vulnerable to the issues described in Microsoft Security Bulletin MS13-004.

If you continue to experience problems, please contact Redgate Support.

Didn't find what you were looking for?