How to determine if a .NET Assembly was compiled in Debug Mode

A colleague asked this question in an email and as often happens I didn't know the answer. However Mark Rees did, and as I couldn't find the answer on the web just thought I would post it here as I thought it was rather a gem:

The best way to do this is to load the assembly in code and grab the System.Diagnostics.DebbugableAttribute attribute from the assembly custom attributes collection and check to see if the "IsJITTrackingEnabled" property is true.

  • If it is true then the assembly was compiled in debug mode; if it'sĀ false then it wasn't.
  • If the attribute is not present then the assembly was also not compiled in debug mode.

Now I know. Thanks Mark!