Why does StackFrame.GetFileName return null?

  • Thread starter Thread starter Adam Smith
  • Start date Start date
A

Adam Smith

With the same program, in my error logging routine, in some deployments
the StackFrame.GetFileName returns null, as does
StackFrame.GetFileLineNumber return 0.

In other deployments, it works fine. Same code.

Anybody help me out?

Thanks.

Adam Smith
 
Is it possible that it works in debug builds but not in release builds? Off
the top of my head, I'd guess that it would need the PDB to get that
information, but just guessing.

Pete
 
That could be it. It's actually *not* working when built into debug,
but moved to another directory without the .pdb.

If so, is there anyway in code to distinguish in C# between a debug
build and release, in the same manner as the DEBUG macros in C++?

Thanks.
 
StackFrame.GetFileName relys on the pdb file, it will only work when symbols
are built.
As for determining if debug is defined, in a standard projects there is a
symbol DEBUG defined which you can use the #if, et al directives, similar to
the way it works in C++. However I don't think debug is defined implicitly
when you build debug symbols, but instead as a seperate define using the
/define compiler argument.

#if DEBUG
// some code
#endif
 
Adam Smith said:
That could be it. It's actually *not* working when built into debug,
but moved to another directory without the .pdb.

Right - that's going to be very similar to the release version then.
The major difference between building release and debug is that
typically a release build doesn't generate debugging information.
If so, is there anyway in code to distinguish in C# between a debug
build and release, in the same manner as the DEBUG macros in C++?

Well, you can use conditional compilation symbols to achieve some of
the same effects.

See http://www.pobox.com/~skeet/csharp/faq/#macros for more
information.
 
Back
Top