Skip to content

StackTrace.GetFrames(true) - GetFileLineNumber() tests #30322

Closed
@gregkalapos

Description

@gregkalapos

In case you create an instance of StackTrace with fNeedFileInfo: true, it will try to deliver you things like file name, line number, column number. - I focus here on line number.

E.g.:

foreach (var frame in new StackTrace(true).GetFrames())
{
   var lineNumber = frame.GetFileLineNumber();
}

There are many known scenarios when GetFileLineNumber() will return 0 despite the StackTrace(true) - e.g. there are no .pdbs present, or portable pdbs pre .NET Framework 4.7.1 and probably more.

Question

Do you have any tests that cover these scenarios and other scenarios when GetFileLineNumber() should not return 0? I looked at the tests for System.Diagnostics.StackTrace and I see some tests that cover line numbers in StackFrameTests.cs but all those create StackFrames manually and pass the line number. StackTraceTests.cs only has a case with Assert.Equal(0, stackFrame.GetFileColumnNumber()) .

But you don’t really seem to test when it should be not 0. Do I see this correctly? Or are there other tests somewhere else?

Context

I’m working on a monitoring tool that reports stack traces, and we also try to show line numbers and of course we want to cover this feature with tests - I thought it’d be nice to see what and how is tested in CoreFX.

I’m not expecting any action on this, it’s more like just a question to answer. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.DiagnosticsquestionAnswer questions and provide assistance, not an issue with source code or documentation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions