CSharpFeeds - All your C# feeds in one place.

Sponsors

Thursday, June 18, 2009

Determine Whether an Assembly was compiled in Debug Mode

by ssmith via Steve Smith's Blog on 6/18/2009 2:48:47 AM

I’m working on a little application right now that provides some insight into the assemblies in use for a given application.  One of the things that I want to be able to show is whether or not each assembly was built in Debug or Release mode.  As you’re no doubt aware, running applications in production that were built in Debug mode can be a major performance problem (at a minimum – depending on what else you have turned on in Debug mode it could also be a security issue).

So I did some binging (followed by some purging? no, wait, that with a hard G sound) and quickly found some sample code that I was able to use in some test code to confirm that it is working.  Fellow MVP Bill McCarthy wrote (like, 5 years ago to the day!) about how to do this in Visual Basic.  Not that I have anything against VB, but my preference since VB6 has been C# (if nothing else, it makes JavaScript much easier to grok), so I had to translate the code into my native tongue, which provides me with something to share with you.  This is literally Bill’s code, translated by me into C#.  Any bugs you can probably assign to me as the translator, rather than Bill as original author.

Check If An Assembly Was Compiled In Debug Mode

private bool IsAssemblyDebugBuild(string filepath)
{
    return IsAssemblyDebugBuild(Assembly.LoadFile(Path.GetFullPath(filepath)));
}
 
private bool IsAssemblyDebugBuild(Assembly assembly)
{
    foreach (var attribute in assembly.GetCustomAttributes(false))
    {
        var debuggableAttribute = attribute as DebuggableAttribute;
        if(debuggableAttribute != null)
        {
            return debuggableAttribute.IsJITTrackingEnabled;
        }
    }
    return false;
}

(subscribe to my blog)
(follow me on twitter)

email it!bookmark it!digg it!

Original Post: Determine Whether an Assembly was compiled in Debug Mode

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us