StackFrame.GetFileLineNumber() Returns 0 in UWP

vaishali chaudhary 1 Reputation point

Hi Team,

I want to get filename and linenumber of exception in UWP App. Below is the code snippet I am using. FileName and LIneNumber are coming as null and 0. The pdb files are available in the Appx and build path. Even in debug mode, I dont get the filename and lineNumber. The same code works in my ConsoleApp but fails in UWP.

   static void Main(string[] args)
        catch (Exception ex)
    private static void LogError(Exception ex)
        StackTrace st = new StackTrace(ex, true);
        StackFrame stackFrame = st.GetFrame(st.FrameCount-1);
        string fileName = stackFrame.GetFileName();
        string methodName = stackFrame.GetMethod().Name;
        int lineNumber = stackFrame.GetFileLineNumber();
Universal Windows Platform (UWP)
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,936 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Roy Li - MSFT 31,266 Reputation points Microsoft Vendor


    Welcome to Microsoft Q&A!

    Although the StackFrame Class is supported to use in UWP, for example, you could call it in a UWP app, but it looks like not all the features of the StackFrame Class are supported, like GetFileLineNumber.

    Generally, if we want to collect or log exception messages, it is recommended to use App Center in UWP apps.

    Thank you.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.