windows 10 exceptions not including line numbers

2019-08-10 14:06发布

I have a Windows 10 Universal App that does not include line numbers in the Exception objects .ToString() method.

If I have a method like

private void ThrowException()
{
    try { throw new Exception("Test"); }
    catch (Exception e) { Debug.WriteLine(ex.ToString()); }
}

When I check the output, I don't see the line number where there exception was thrown. I added a Post Build event to the project:

xcopy $(ProjectDir)$(OutDir)*.pdb $(ProjectDir)$(OutDir)AppX\*.pdb

The pdb file is in the Debug folder but not in the AppX folder.

What am I missing? Thanx,

EDIT

I created a new project to test this. I have a single page (MainPage.xaml). Here is the code behind file:

using System;
using Windows.UI.Popups;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

namespace App2
{
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            ThrowException();
        }

        private async void ThrowException()
        {
            try { throw new Exception("Test"); }
            catch (Exception ex) { await new MessageDialog(ex.ToString()).ShowAsync(); }
        }
    }
}

As before, I added the post build event macro:

xcopy $(ProjectDir)$(OutDir)*.pdb $(ProjectDir)$(OutDir)AppX\*.pdb

I compiled in the Release configuration and insured the "Compile with .NET native tool chain" option is checked.

The Appx folder in C:\VS2015\App2\App2\bin\x86\Release\AppX does have the files App2.dll and App2.pdb present.

When I run the app, I get the following in the popup dialog:

System.Exception: Test
  at SharedLibrary!<BaseAddress>+0x122d16

Thanx

EDIT 2

I also tried this in Debug without the native tool chain. In that case, I did not see the pdb file in the AppX folder under Debug

The message in that case was:

System.Exception: Test
  at App2.MainPage.<ThrowException>d_2.MoveNext()

Thanx

1条回答
Animai°情兽
2楼-- · 2019-08-10 15:01

I made an error in my original answer and was using immediate window output and not what the code could get from the exception object.

After more research, it looks like this is no longer supported.

See corefx #1420 and related corefx #1797.

Also, there is this reference on SO: How to get StackTrace without Exception in Windows Universal 10 App

查看更多
登录 后发表回答