Windows 10 异常不包括行号 [英] windows 10 exceptions not including line numbers

查看:23
本文介绍了Windows 10 异常不包括行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Windows 10 通用应用程序,它的异常对象 .ToString() 方法中不包含行号.

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

如果我有类似的方法

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

当我检查输出时,我没有看到抛出异常的行号.我在项目中添加了一个 Post Build 事件:

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

pdb 文件位于 Debug 文件夹中,但不在 AppX 文件夹中.

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

我错过了什么?谢谢,

编辑

我创建了一个新项目来测试这个.我有一个页面 (MainPage.xaml).这是文件背后的代码:

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

我在发布配置中编译并确保选中了使用 .NET 本机工具链编译"选项.

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

C:\VS2015\App2\App2\bin\x86\Release\AppX 中的 Appx 文件夹确实存在文件 App2.dll 和 App2.pdb.

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

谢谢

编辑 2

我也在没有本机工具链的情况下在调试中尝试过这个.在那种情况下,我没有在 Debug

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

这种情况下的消息是:

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

谢谢

推荐答案

我在原始答案中犯了一个错误,使用的是即时窗口输出,而不是代码可以从异常对象中获得的内容.

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.

参见 corefx #1420 和相关的 corefx #1797.

此外,还有关于 SO 的参考:如何在 Windows Universal 10 应用程序中无异常地获取 StackTrace

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

这篇关于Windows 10 异常不包括行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆