ViewWillAppear(Boolean animated) - (registrar.m:6562) - System.NullReferenceException

MuthuRajMuthuRaj USMember ✭✭
edited September 2016 in Xamarin.iOS

Hi Everybody,
I am currently working in a client project that has a mobile app developed in Native Xamarin (Android and iOS). This app is integrated with HockeyApp and the crash logs will be reflected in our HockeyApp account. Currently, I am facing an app crash. This issue is however, very hard to reproduce. In my app, I am having Screen A, from this I am navigating to Screen B through a button click. While, navigating back to Screen A, I am getting a crash that is happening due to a NullReferenceException in "ViewWillAppear" method. My HockeyApp crash logs shows like this:

  View Raw LogView in HockeyApp for Mac Last Exception Backtrace:
  1 CoreFoundation  __exceptionPreprocess + 131
  2 libobjc.A.dylib objc_exception_throw + 36
  3 CoreFoundation  -[NSException raise] + 6
  4 MobileApp   wrapper_managed_to_native_Xamarin_ObjCRuntime_Messaging_void_objc_msgSend_intptr_intptr + 78
  5 MobileApp   HockeySDK_CrashOnly_iOSBindings_HockeyApp_iOS_BITHockeyManager_ConvertToNsExceptionAndAbort_object + 306
  6 MobileApp       
  HockeySDK_CrashOnly_iOSBindings_HockeyApp_iOS_BITHockeyManager__StartManagerm__0_object_System_UnhandledExceptionEventArgs + 18
  7 MobileApp   wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 254
  8 MobileApp   mono_jit_runtime_invoke (mini-runtime.c:2562)
  9 MobileApp   mono_runtime_invoke (object.c:2897)
  10    MobileApp   call_unhandled_exception_delegate (object.c:4040)
  11    MobileApp   mono_unhandled_exception (object.c:4130)
  12    MobileApp   mono_handle_exception_internal (mini-exceptions.c:1665)
  13    MobileApp   mono_handle_exception (mini-exceptions.c:1950)
  14    MobileApp   handle_signal_exception (exceptions-arm.c:529)
  15    ??? 0x0 + 0
  16    MobileApp   wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 254
  17    MobileApp   mono_jit_runtime_invoke (mini-runtime.c:2562)
  18    MobileApp   mono_runtime_invoke (object.c:2897)
  19    MobileApp   native_to_managed_trampoline_16(objc_object*, objc_selector*, _MonoMethod**, signed char, char const*, char const*, char const*)   
  (registrar.m:543)
  20    MobileApp   -[HomeViewController viewWillAppear:] (registrar.m:6562)
  21    UIKit   -[UIViewController _setViewAppearState:isAnimating:] + 544
  22    UIKit   -[UIViewController __viewWillAppear:] + 142
  23    UIKit   -[UINavigationController _startCustomTransition:] + 1096
  24    UIKit   -[UINavigationController _startDeferredTransitionIfNeeded:] + 630
  25    UIKit   -[UINavigationController __viewWillLayoutSubviews] + 48
  26    UIKit   -[UILayoutContainerView layoutSubviews] + 194
  27    UIKit   -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1288
  28    QuartzCore  -[CALayer layoutSublayers] + 124
  29    QuartzCore  CA::Layer::layout_if_needed(CA::Transaction*) + 352
  30    QuartzCore  CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 14
  31    QuartzCore  CA::Context::commit_transaction(CA::Transaction*) + 368
  32    QuartzCore  CA::Transaction::commit() + 562
  33    UIKit   _UIApplicationFlushRunLoopCATransactionIfTooLate + 196
  34    UIKit   __handleEventQueue + 1348
  35    CoreFoundation  __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 10
  36    CoreFoundation  __CFRunLoopDoSources0 + 436
  37    CoreFoundation  __CFRunLoopRun + 760
  38    CoreFoundation  CFRunLoopRunSpecific + 484
  39    CoreFoundation  CFRunLoopRunInMode + 102
  40    GraphicsServices    GSEventRunModal + 154
  41    UIKit   -[UIApplication _run] + 572
  42    UIKit   UIApplicationMain + 148
  43    MobileApp   wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr (:3860)
  44    MobileApp   Xamarin_iOS_UIKit_UIApplication_Main_string___string_string (UIApplication.cs:79)
  45    MobileApp   MobileApp_Application_Main_string__ (Main.cs:16)
  46    MobileApp   wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 254
  47    MobileApp   mono_jit_runtime_invoke (mini-runtime.c:2562)
  48    MobileApp   mono_runtime_invoke (object.c:2897)
  49    MobileApp   mono_runtime_exec_main (object.c:4223)
  50    MobileApp   xamarin_main (monotouch-main.m:454)
  51    MobileApp   main (main.armv7.m:92)
  52    ??? 0x0 + 0

My ViewWillAppear method is already handled using exception handling:

public override void ViewWillAppear (bool animated)
{   
    base.ViewWillAppear (animated);
    try { 
        AbbreviationString = ParentViewController.ShortString;
        if (AbbreviationString !=null) { 
            userLabel.Text = AbbreviationString;
        }
        if (TextLabel != null) {
            TextLabel.Layer.BorderColor = UIColor.FromRGB (1, 39, 134).CGColor;
            TextLabel.Layer.BackgroundColor = UIColor.FromRGB (242, 242, 242).CGColor;
            TextLabel.TextColor = UIColor.FromRGB (1, 39, 134);
        }
        HomeButton.SetTitleColor (UIColor.Black, UIControlState.Normal);
    } catch (Exception ex) {
        Console.WriteLine ("Exception Occured: "+ex);
    }     
    if(_loader !=null)
        _loader.Hide();            
} 

So, I believe it is not happening in my code handling. Could someone help me on this. I would like to know if this issue is due to the registrar.m class.

Sign In or Register to comment.