【问题标题】:How to show my source code in stack trace for Xamarin iOS app?如何在 Xamarin iOS 应用程序的堆栈跟踪中显示我的源代码?
【发布时间】:2018-05-02 23:13:16
【问题描述】:

我的 Xamarin iOS 应用程序因错误“无法识别的选择器发送到实例...”而崩溃,但堆栈跟踪和调用堆栈都没有任何有用的信息来说明我的源代码中可能出现的问题。我正在使用 Visual Studio for Mac,并且该应用程序正在 iOS 模拟器上运行。是否需要启用任何选项才能在堆栈跟踪中显示我的源代码?

Unhandled Exception:
Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[NSObject doesNotRecognizeSelector]: unrecognized selector sent to instance 0x600000016d80
Native stack trace:
    0   CoreFoundation                      0x000000010579e12b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00000001066d8f41 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010581f024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x0000000105720f78 ___forwarding___ + 1432
    4   CoreFoundation                      0x0000000105720958 _CF_forwarding_prep_0 + 120
    5   Foundation                          0x0000000103997f35 __NSFireDelayedPerform + 409
    6   CoreFoundation                      0x000000010572e174 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
    7   CoreFoundation                      0x000000010572de32 __CFRunLoopDoTimer + 1026
    8   CoreFoundation                      0x000000010572d9ea __CFRunLoopDoTimers + 266
    9   CoreFoundation                      0x0000000105725404 __CFRunLoopRun + 2308
    10  CoreFoundation                      0x0000000105724889 CFRunLoopRunSpecific + 409
    11  GraphicsServices                    0x0000000108cfb9c6 GSEventRunModal + 62
    12  UIKit                               0x00000001013375d6 UIApplicationMain + 159
    13  ???                                 0x00000001179fbe98 0x0 + 4691312280
    14  ???                                 0x00000001179fbac3 0x0 + 4691311299

更新:

问题似乎与模拟器的.dSYM files not being generated 有关。

【问题讨论】:

  • 我不明白你的问题。您的源代码中已经突出显示了引发异常的行;这是您在 Main 函数中拥有的唯一一行代码。这是堆栈跟踪或调用堆栈中与您自己的代码相关的唯一可用信息。堆栈跟踪或调用堆栈可以向您显示的绝对是已经显示的内容。
  • @KenWhite Xamarin iOS 总是在 Main.cs 中显示同一行代码,因为那是应用程序的入口点,我所做的是继续应用程序执行,然后出现堆栈跟踪应用程序输出显示在 Main.cs 以外的其他文件中发生异常的正确行。我认为这是框架或运行时中的错误,但对于这个特定错误,我无法通过继续执行应用程序来获得任何有用的信息。
  • 在附加的mtouch参数中添加-gcc_flags -ObjC或修改LinkWith属性,详情参考here

标签: visual-studio xamarin xamarin.ios mono


【解决方案1】:

这是我添加到我的 Application.cs 类中以更好地查看异常信息:

    static void Main(string[] args)
    {
#if DEBUG
        try
        {
#endif
            UIApplication.Main(args, null, "AppDelegate");
#if DEBUG
        }
        catch (Exception ex)
        {
            var msg = ex.Message;
            var temp = ex.StackTrace;
            if(System.Diagnostics.Debugger.IsAttached)
                System.Diagnostics.Debugger.Break();
            throw;
        }
#endif
    }

【讨论】:

  • 这个问题似乎与模拟器的.dSYM files not being generated 有关,有什么解决方法吗?
  • 不是一个完美的解决方案,但我现在至少可以在控制台中看到堆栈跟踪。
【解决方案2】:

您可以在 xamarin 源代码中进行跟踪。 Details specified in Microsoft documentation.

您还可以通过更改 Xamarin 选项 as specified in Xamarin forums 在调试期间获取更多诊断详细信息。

【讨论】:

    猜你喜欢
    • 2020-10-25
    • 1970-01-01
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 2012-08-21
    • 2010-09-13
    • 2023-03-09
    • 2017-07-06
    相关资源
    最近更新 更多