c# - 将 iOS 应用程序升级到 Xamarin 统一 API

标签 c# ios xamarin xamarin.ios

尝试启动我使用 Xamarin Studio 中的自动升级工具升级到统一 API 的应用程序时出现异常。我可以看到启动画面在 iPhone 模拟器中显示了大约一秒钟,然后在 Main 方法中抛出了以下异常。

Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
Native stack trace:
    0   CoreFoundation                      0x00940a94 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x087ffe02 objc_exception_throw + 50
    2   CoreFoundation                      0x007ee3a1 -[__NSArrayM insertObject:atIndex:] + 881
    3   CoreFoundation                      0x007ee001 -[__NSArrayM addObject:] + 65
    4   UIKit                               0x0342e9b6 -[UINavigationController _navigationItems] + 341
    5   UIKit                               0x0342c3ac -[UINavigationController initWithCoder:] + 1009
    6   UIKit                               0x0364c834 -[UIClassSwapper initWithCoder:] + 279
    7   UIKit                               0x03846e99 UINibDecoderDecodeObjectForValue + 739
    8   UIKit                               0x03846bae -[UINibDecoder decodeObjectForKey:] + 320
    9   UIKit                               0x0333a812 -[UINavigationBar initWithCoder:] + 472
    10  UIKit                               0x03846e99 UINibDecoderDecodeObjectForValue + 739
    11  UIKit                               0x03846bae -[UINibDecoder decodeObjectForKey:] + 320
    12  UIKit                               0x0332f9a9 -[UINavigationItem initWithCoder:] + 899
    13  UIKit                               0x03846e99 UINibDecoderDecodeObjectForValue + 739
    14  UIKit                               0x03846bae -[UINibDecoder decodeObjectForKey:] + 320
    15  UIKit                               0x033f217e -[UIViewController initWithCoder:] + 528
    16  UIKit                               0x03455f5e -[UITabBarController initWithCoder:] + 68
    17  UIKit                               0x0364c834 -[UIClassSwapper initWithCoder:] + 279
    18  UIKit                               0x03846e99 UINibDecoderDecodeObjectForValue + 739
    19  UIKit                               0x03846bae -[UINibDecoder decodeObjectForKey:] + 320
    20  UIKit                               0x0364c403 -[UIRuntimeConnection initWithCoder:] + 148
    21  UIKit                               0x03846e99 UINibDecoderDecodeObjectForValue + 739
    22  UIKit                               0x038470aa UINibDecoderDecodeObjectForValue + 1268
    23  UIKit                               0x03846bae -[UINibDecoder decodeObjectForKey:] + 320
    24  UIKit                               0x0364b43d -[UINib instantiateWithOwner:options:] + 1411
    25  UIKit                               0x039f4ace -[UIStoryboard instantiateViewControllerWithIdentifier:] + 220
    26  UIKit                               0x039f4c5b -[UIStoryboard instantiateInitialViewController] + 78
    27  UIKit                               0x032355e7 -[UIApplication _loadMainStoryboardFileNamed:bundle:] + 99
    28  UIKit                               0x03235964 -[UIApplication _loadMainInterfaceFile] + 292
    29  UIKit                               0x03233d35 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1575
    30  UIKit                               0x03257905 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke3171 + 68
    31  UIKit                               0x03230bae -[UIApplication workspaceDidEndTransaction:] + 163
    32  FrontBoardServices                  0x0b013ccc __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
    33  FrontBoardServices                  0x0b0137a3 __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
    34  FrontBoardServices                  0x0b0311cb -[FBSSerialQueue _performNext] + 184
    35  FrontBoardServices                  0x0b031602 -[FBSSerialQueue _performNextFromRunLoopSource] + 52
    36  FrontBoardServices                  0x0b0308fe FBSSerialQueueRunLoopSourceHandler + 33
    37  CoreFoundation                      0x0085ae7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    38  CoreFoundation                      0x00850b0b __CFRunLoopDoSources0 + 523
    39  CoreFoundation                      0x0084ff28 __CFRunLoopRun + 1032
    40  CoreFoundation                      0x0084f866 CFRunLoopRunSpecific + 470
    41  CoreFoundation                      0x0084f67b CFRunLoopRunInMode + 123
    42  UIKit                               0x03230497 -[UIApplication _run] + 540
    43  UIKit                               0x03235cc1 UIApplicationMain + 160
    44  ???                                 0x17eb7288 0x0 + 401306248
    45  ???                                 0x17eb7080 0x0 + 401305728
    46  ???                                 0x17eb5210 0x0 + 401297936
    47  ???                                 0x17eb4f48 0x0 + 401297224
    48  ???                                 0x17eb50d8 0x0 + 401297624
    49  myAppiOS                         0x00207d9b mono_jit_runtime_invoke + 715
    50  myAppiOS                         0x002a66ef mono_runtime_invoke + 127
    51  myAppiOS                         0x002ab8e1 mono_runtime_exec_main + 401
    52  myAppiOS                         0x002ab697 mono_runtime_run_main + 711
    53  myAppiOS                         0x00167fad mono_jit_exec + 93
    54  myAppiOS                         0x00384bd1 xamarin_main + 2497
    55  myAppiOS                         0x00385562 main + 114
    56  libdyld.dylib                       0x08cd9a21 start + 1
    57  ???                                 0x00000003 0x0 + 3

在默认的 Main 方法中:

using System.Collections.Generic;
using System.Linq;

using Foundation;
using UIKit;

namespace myAppiOS
{
    public class Application
    {
        // This is the main entry point of the application.
        static void Main (string[] args)
        {
            // if you want to use a different Application Delegate class from "AppDelegate"
            // you can specify it here.
            UIApplication.Main (args, null, "AppDelegate");
        }
    }
}

有什么想法吗?

最佳答案

我只有故障排除技巧可以分享。

问题出在 StackTrace 的第 3 行:

2 CoreFoundation 0x007ee3a1 -[__NSArrayM insertObject:atIndex:] + 881

很明显,您正在添加一个项目,而 libobjc.A.dylib 本身正在崩溃:

1 libobjc.A.dylib 0x087ffe02 objc_exception_throw + 50 2

为了诊断根本原因,需要使用经典的 ASP 故障排除方法。 Debug.Print 语句无处不在!

您实际上必须在代码中搜索要将项目添加到集合的位置。那个地方很可能在 instantiateViewControllerWithIdentifier 调用中。

因为异常被抛出在您单步执行代码之前,唯一的其他选择(除了内存转储调试)是注释掉或调试。打印所有调用以缩小问题范围!一个一个:(

就是这样的 PITA 和 I do empathize with you .我认为这是由于根据错误消息 object cannot be nil

添加了一个空对象

它可以是任何东西,添加 null 可能是另一个问题的征兆。 也许您要添加的项目太大,也许它超出了数组的范围,也许您只需要清理解决方案并重新部署。

如果您可以通过 UIApplication.Main (args, null, "AppDelegate");,尝试打开异常可能会有所帮助,例如:https://stackoverflow.com/a/32754919/495455

关于c# - 将 iOS 应用程序升级到 Xamarin 统一 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32702601/

相关文章:

ios - 创建用于读取 QR 码的相机叠加层

ios - 在标签栏 Controller 中的推送 View Controller 中显示工具栏

ios - Xamarin.forms,删除 iOS 10 中的状态栏

ios - 缺少 Windows 选项的远程 iOS 模拟器?

c# - 从域\别名组合获取显示名称

c# - 如何使用 EPPlus 在 Excel 文件 (.XLSX) 中找到我的数据范围?

ios - Swift - 为单例设置委托(delegate)

c# - LINQ - 通过 WHERE 子句查询大约 6000 条唯一记录

C#:如何从另一台局域网计算机和 Windows 身份验证连接到 sql server 2008 express?

c# - 将列表传递给 RootElement c# 中的部分