StackFrame debug information

N

newscorrespondent

I have compiled in DEBUG mode but don't get the debug information from
StackFrame class. Is there a specific setting I need to use so that
information is included for a debug build.

Thanks
Tom
 
B

Barry Kelly

I have compiled in DEBUG mode but don't get the debug information from
StackFrame class. Is there a specific setting I need to use so that
information is included for a debug build.

How are you using it? StackFrame is usually used with StackTrace, and it
isn't sensitive to DEBUG (although some inlining may occur at runtime
when compiled in Release mode). To get file information, you must always
create a PDB and distribute it - but it isn't necessary to use full
debugging. Perhaps you aren't using the StackTrace constructor which
takes the boolean argument to collect file information?

Example:

---8<---
using System;
using System.Diagnostics;

class App
{
static void Main()
{
StackFrame frame = new StackTrace(true).GetFrame(0);
Console.WriteLine("{0} ({1})", frame.GetFileName(),
frame.GetFileLineNumber());
}
}
--->8---

Compiled with:

---8<---
csc -debug:pdbonly -optimize+ Test.cs
--->8---

When run, it produces this output on my machine:

---8<---
c:\proj\Test\Test.cs (8)
--->8---

-- Barry
 

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