Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional DEBUG - Does it still compile into RELEASE code?

I know that if I mark code as DEBUG code it won't run in RELEASE mode, but does it still get compiled into an assembly? I just wanna make sure my assembly isn't bloated by extra methods.

[Conditional(DEBUG)]
private void DoSomeLocalDebugging()
{
   //debugging
}
like image 558
myermian Avatar asked Aug 13 '10 13:08

myermian


People also ask

Can you debug in Release mode?

You can now debug your release build application. To find a problem, step through the code (or use Just-In-Time debugging) until you find where the failure occurs, and then determine the incorrect parameters or code.

What is difference between debug and Release build?

Debug Mode: When we are developing the application. Release Mode: When we are going to production mode or deploying the application to the server. Debug Mode: The debug mode code is not optimized. Release Mode: The release mode code is optimized.

What is difference between debug and Release in Visual Studio?

Visual Studio projects have separate release and debug configurations for your program. You build the debug version for debugging and the release version for the final release distribution. In debug configuration, your program compiles with full symbolic debug information and no optimization.

How much faster is Release than debug?

But the reality is debug build is much faster than release build. The release build normally takes more than 0.30ms, while the debug build takes under 0.3.


1 Answers

Yes, the method itself still is built however you compile.

This is entirely logical - because the point of Conditional is to depend on the preprocessor symbols defined when the caller is built, not when the callee is built.

Simple test - build this:

using System;
using System.Diagnostics;

class Test
{
    [Conditional("FOO")]
    static void CallMe()
    {
        Console.WriteLine("Called");
    }

    static void Main()
    {
        CallMe();
    }
}

Run the code (without defining FOO) and you'll see there's no output, but if you look in Reflector you'll see the method is still there.

To put it another way: do you think the .NET released assemblies (the ones we compile against) are built with the DEBUG symbol defined? If they're not (and I strongly suspect they're not!) how would we be able to call Debug.Assert etc?

Admittedly when you're building private methods it would make sense not to include it - but as you can see, it still is built - which is reasonable for simplicity and consistency.

like image 97
Jon Skeet Avatar answered Oct 03 '22 06:10

Jon Skeet