Click here to Skip to main content
15,565,351 members
Articles / Programming Languages / C#
Posted 3 Feb 2012

Tagged as


2 bookmarked

(C#) Determining whether the current build mode is Debug or Release

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
3 Feb 2012CPOL
While I think alternative 3 could be quite useful I often have access to the assembly name and not the actual file name.For example the assembly name might be:Company.ProductWhereas the file name might be:Company.Product.dllThere are times when I'll fully qualify a class such...
While I think alternative 3 could be quite useful I often have access to the assembly name and not the actual file name.
For example the assembly name might be:
Whereas the file name might be:

There are times when I'll fully qualify a class such as:
"Company.Product.Namespace.MyClass, Company.Product"
and therefore I have the name of the assembly, but not the name of the file.

The fully qualified class name is useful to pass to Type.GetType(string) when passing only the full class name doesn't seem to work.

While adding ".dll" on the end is not difficult I do think there are times when the following alternative might be useful.

Instead of passing the file name you simply pass the assembly name. Which does tend to be the file name without the .dll.

Instead of using the Assembly.LoadFile function it uses Assembly.Load.

public static bool IsInDebugMode(string assemblyName)
    var assembly = System.Reflection.Assembly.Load(assemblyName);
    var attributes = assembly.GetCustomAttributes(typeof(System.Diagnostics.DebuggableAttribute), false);
    if (attributes.Length > 0)
        var debuggable = attributes[0] as System.Diagnostics.DebuggableAttribute;
        if (debuggable != null)
            return (debuggable.DebuggingFlags & System.Diagnostics.DebuggableAttribute.DebuggingModes.Default) == System.Diagnostics.DebuggableAttribute.DebuggingModes.Default;
            return false;
        return false;

However I'm sure there are plenty of times when people have the file name and therefore the previous alternative would be more suited.

So the function used depends on whether the assembly info you have access to is the assembly name or the file name.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Australia Australia
Founder of

Comments and Discussions

GeneralGood job, I updated my tip at Pin
Huisheng Chen3-Feb-12 23:56
Huisheng Chen3-Feb-12 23:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.