question

vaishalichaudhary-4785 avatar image
0 Votes"
vaishalichaudhary-4785 asked pallammadhukar commented

StackFrame.GetFileLineNumber() Returns 0 in UWP

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)
     {
         try
         {
             Convert.ToInt32("xyx");
         }
         catch (Exception ex)
         {
             LogError(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();
     }
 }

dotnet-csharpwindows-uwp
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Due to certain missing features, some authors recommend using the Environment.StackTrace string. It can be also parsed. Did you check if it includes the details?

0 Votes 0 ·

tried to parse Enviroment.Stacktrace and ex.StackTrace but no Luck.

0 Votes 0 ·

1 Answer

RoyLi-MSFT avatar image
0 Votes"
RoyLi-MSFT answered pallammadhukar commented

Hello,

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.


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Using AppCenter is not suitable for my solution.
I have a SDK built in UWP with underlaying C++ solution. My UWP Project is a class Library.
My SDK uses C++ API to log. API: LogMessage(string msg, LogLevel level, int lineNumber, string MethodName, string FileName);

Hence, My UWP SDK is suppose to fetch this info and send to API. I tried to parse Enviroment.Stacktrace and ex.StackTrace but no Luck. Is it possible to get the all these important feature in StackFrame for UWP.



0 Votes 0 ·
RoyLi-MSFT avatar image RoyLi-MSFT vaishalichaudhary-4785 ·

Is it possible to get the all these important feature in StackFrame for UWP.

I have to say currently, no. I could help you submit a request about this via our channel. And you could also submit a feedback about this in the Feedback Hub. You could find the Feedback Hub in the Start Menu.

0 Votes 0 ·

@RoyLi-MSFT Is this still not possible today?

0 Votes 0 ·