Release Mode Compiling with System.Diagnostics.Debug

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?
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
G

Guest

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?
 
N

Nicholas Paldino [.NET/C# MVP]

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top