Release Mode Compiling with System.Diagnostics.Debug

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Suppose that you have below property in some class,
#if DEBUG
public string DebugInfo
{
get
{
return "INDEX : " + _name + "\n" +
"Index Owner : " + _owner.Name + "\n" +
"Index Column Count: " + _columns.Count + "\n";
}
}
#endif

Somewhere you call this property get function as below

System.Diagnostics.Debug.Print(index.DebugInfo);

In release mode this code does not compile. The error is
'Sesam.Studio.Stat.Database.Index' does not contain a definition for
'DebugInfo' .
It got confused of the error because I write this in a Debug call. Are
Debug calls excluded in Release mode or not? Why doesn't above code compile?
 
Haldun,

Calls to the Debug class are not removed in release mode. Since you are
not exposing the type in release mode, you are essentially trying to access
a type that doesn't exist.

Hope this helps.
 
Thanks Nicholas for the answer.
In other words, is there any use or benefit of calls to Debug class in
release mode? I couldn't see any. In my opinion, these calls must be removed
from the code in release mode compilation. If they are removed, I won't have
to expose functions, properties that are only for debug purposes like my
DebugInfo. Is this clear?

Nicholas Paldino said:
Haldun,

Calls to the Debug class are not removed in release mode. Since you are
not exposing the type in release mode, you are essentially trying to access
a type that doesn't exist.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Haldun ALIML said:
Suppose that you have below property in some class,
#if DEBUG
public string DebugInfo
{
get
{
return "INDEX : " + _name + "\n" +
"Index Owner : " + _owner.Name + "\n" +
"Index Column Count: " + _columns.Count + "\n";
}
}
#endif

Somewhere you call this property get function as below

System.Diagnostics.Debug.Print(index.DebugInfo);

In release mode this code does not compile. The error is
'Sesam.Studio.Stat.Database.Index' does not contain a definition for
'DebugInfo' .
It got confused of the error because I write this in a Debug call. Are
Debug calls excluded in Release mode or not? Why doesn't above code
compile?
 
Halsdun,

It's not a matter of using the Debug class in release mode. It's still
going to do whatever you tell it to do, it's a class, like any other.

If you don't want the calls there, then you should wrap those sections
of code in a pre-processor directive (#if), or, for whole methods, you can
use the ConditionalAttribute.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Haldun ALIML said:
Thanks Nicholas for the answer.
In other words, is there any use or benefit of calls to Debug class in
release mode? I couldn't see any. In my opinion, these calls must be
removed
from the code in release mode compilation. If they are removed, I won't
have
to expose functions, properties that are only for debug purposes like my
DebugInfo. Is this clear?

Nicholas Paldino said:
Haldun,

Calls to the Debug class are not removed in release mode. Since you
are
not exposing the type in release mode, you are essentially trying to
access
a type that doesn't exist.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Haldun ALIML said:
Suppose that you have below property in some class,
#if DEBUG
public string DebugInfo
{
get
{
return "INDEX : " + _name + "\n" +
"Index Owner : " + _owner.Name + "\n" +
"Index Column Count: " + _columns.Count + "\n";
}
}
#endif

Somewhere you call this property get function as below

System.Diagnostics.Debug.Print(index.DebugInfo);

In release mode this code does not compile. The error is
'Sesam.Studio.Stat.Database.Index' does not contain a definition for
'DebugInfo' .
It got confused of the error because I write this in a Debug call. Are
Debug calls excluded in Release mode or not? Why doesn't above code
compile?
 
Back
Top