Line numbers in exception stack on winRT

蹲街弑〆低调 提交于 2019-12-21 05:42:09

问题


We have a project for windows store app using WinRT (and XAML, C#). The problem is, that when some exception is thrown and I log the exception using Debug.WriteLine(ex);, there are no line numbers, so I do not know, where actually was the exception thrown. I have of course DEBUG configuration with "full" symbols set in Project Properties > Build > Advanced > Debug Info.

At first I thougth that it must be something in our project. HOwever, when I downlaoded some samples from microsoft and put there the following code, the exception still does not have line numbers.

        try
        {
            throw new Exception("Test");
        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex);
        }

If I put the code above for example into OnNavigatedTo method, I get:

System.Exception: Test
   at SDKTemplate.MainPage.OnNavigatedTo(NavigationEventArgs e)

No line number there ...

In articles , books etc. there is no mention of the fact, that there should be no line numbers, but maybe I am missing something? Can it be related to version of VS? I am using VS2013. Or some system wide settings?


回答1:


What's happening is that Visual Studio isn't including the .pdb file (symbols) in the path where it executes the app. On my machine, the path to the executable looks like this:

C:\Users\msmall\Documents\Visual Studio 2013\Projects\DebugLineNUmbers\DebugLineNUmbers\bin\Debug\AppX

That's where VS packages up the executable and deploys it to the local machine to be run. There's no .pdb file inside the AppX folder. You end up with this:

System.Exception: Test
  at DebugLineNUmbers.MainPage.OnNavigatedTo(NavigationEventArgs e)

However, you can move the .pdb from the Debug folder - just one level up - into the AppX folder and end up with the line numbers:

System.Exception: Test
  at DebugLineNUmbers.MainPage.OnNavigatedTo(NavigationEventArgs e) in
  c:\Users\msmall\Documents\Visual Studio 2013
  \Projects\DebugLineNUmbers\DebugLineNUmbers\MainPage.xaml.cs:line 36



回答2:


Maybe this post can help: Line numbers




回答3:


I can't add comments yet so here's a new answer which adds on to the accepted one.

Navigate to:

Project->[Project Name] Properties...->Build Events->Post-build event command line:

Add the following line to copy the pdb file to the AppX directory:

xcopy /y "$(TargetDir)$(TargetName).pdb" "$(TargetDir)\AppX"


来源:https://stackoverflow.com/questions/26867558/line-numbers-in-exception-stack-on-winrt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!