Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading iOS app to Xamarin Unified API

I get an exception when trying to start my app that I upgraded to unified API with the automated upgrading tool in Xamarin Studio. I can see the splash screen showing up for about a second in the iPhone-simulator and then the following exception is thrown in the Main method.

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

This in the default Main method:

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");
        }
    }
}

Any ideas?

like image 243
Flo Avatar asked Sep 21 '15 18:09

Flo


People also ask

Can I build iOS app on Windows Xamarin?

To build Xamarin. iOS apps with Visual Studio 2019 or Visual Studio 2022 on Windows, you will need: A Windows machine with Visual Studio 2019 or Visual Studio 2022 installed. This can be a physical or a virtual machine.

Is Xamarin being discontinued?

Xamarin support will end on May 1, 2024 for all Xamarin SDKs. Android 13 and Xcode 14 SDKs (iOS and iPadOS 16, macOS 13) will be the final versions Xamarin will target.

Will Maui replace Xamarin native?

Forms. . NET Multi-platform App UI (MAUI) is a multi-platform technology for developing mobile (iOS and Android) and desktop (Windows and Mac) applications.

Is Xamarin getting deprecated?

In May 2020, Microsoft announced that Xamarin. Forms, a major component of its mobile app development framework, would be deprecated in November 2021 in favour of a new . Net based product called MAUI - Multiform App User Interface.


1 Answers

I only have troubleshooting tips to share.

The problem is in the 3rd line of the StackTrace:

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

Its obvious that you're adding an item and the libobjc.A.dylib thing is crapping itself:

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

In order to diagnose the root cause classic ASP troubleshooting methodology is required. Debug.Print statements everywhere!

You literally have to search your code for where you are adding items to a collection. And that somewhere is likely to be in the instantiateViewControllerWithIdentifier call.

Because the exception is thrown before you can step through the code, the only other option (apart from memory dump debugging) is to comment out or Debug.Print all the calls to narrow down the problem! One by one :(

Its such a PITA and I do empathize with you. I reckon its due to a null object being added as per the error message object cannot be nil

It could be anything though and adding null is probably a symptom of another problem. Maybe the item you're adding is too large, maybe its exceeding the bounds of the array, maybe you just need to Clean Solution and redeploy.

Perhaps try turning on exceptions might help if you can get past the UIApplication.Main (args, null, "AppDelegate");, eg: https://stackoverflow.com/a/32754919/495455

like image 180
Jeremy Thompson Avatar answered Oct 07 '22 17:10

Jeremy Thompson