I have a quick-and-dirty unit test framework for my ASP.NET application — an ASPX page with a method that compares expected and actual results and creates a table. It compiles as needed and lets me create and run a bevy of tests quickly, even without VS.NET running.
Here’s an example call:
PrintResult(
expected: "$A$1",
actual: RST.ExcelReference.FormatReferences("{{REF:1:0:1:0}}", false, 0, 0),
arguments: "RST.ExcelReference.FormatReferences(\"{{REF:1:0:1:0}}\", false, 0, 0)");
(Named arguments added for clarity.)
As you can imagine, synchronizing the actual call and the display of that call is a pain.
I know I can’t examine argument values in Environment.StackTrace, only the method definition and line number. But in my case, I don’t need actual argument values. I’m generally calling this method using literals as arguments, so all I need is the line of source code for the entry point into PrintResult() in the Stack Trace.
The source code seems to be available to ASP.NET somehow, as it appears when there is an unhandled exception. How can I access it?
Environment.StackTraceprovides you with the file name and line number in each line of the stack trace. It is clearly formatted and should be easily parseable. From the documentation:In the question you implied that
Environment.StackTraceis not the answer to your question, but it seems like you should be able to parse out the source file name and line number, then go read that line from the file. What am I missing?