How to prevent iOS crash reporters from crashing MonoTouch apps?

DanAbramovDanAbramov RUMember, Beta ✭✭
edited January 2013 in Xamarin.iOS

There are plenty iOS crash reporting libraries in iOS, including TestFlight and HockeyApp. If you don't want to depend on services, you can still use libraries like PLCrashReporter. Binding these libraries is fairly trivial because their public API usually consists of a couple of classes with several initialization methods.

However, when trying to use TestFlight, and later HockeyApp in our application, our app began to randomly crash. Turns out, this is a known issue reported several times, but Xamarin doesn't warn about it, it is relatively obscure and we found it the hard way.

We have learned that all iOS crash reporters prevent Mono from catching null reference exceptions:

try {
    object o = null;
    o.GetHashCode ();
} catch {
    // Catch block isn't called with crash reporting enabled.
    // Instead, the app will crash.

Why does this happen? Quoting Rolf, a Xamarin developer,

A null reference exception is actually a SIGSEGV signal at first. Usually the

mono runtime handles this and translates it into a nullreference exception,
allowing the execution to continue. The problem is that SIGSEGV signals are a
very bad thing in ObjC apps (and when it occurs outside of managed code), so
any crash reporting solution will report it as a crash (and kill the app) -
this happens before MonoTouch gets a chance to handle the SIGSEGV, so there is
nothing MonoTouch can do about this.

I'm sure many use TestFlight in MonoTouch apps without knowing it causes crashes.
Isn't it ironic?

How do you make crash reporting libraries not crash MonoTouch apps?

(This question was originally posted on StackOverflow)


  • NicWiseNicWise NZMember, Insider, Beta mod

    Awesome, Dan, and also awesome timing - planning on integrating something like this for shortly.... :)

  • ParadoxParadox CAMember ✭✭

    Thanks a lot for this info! I had a slightly different issue but this solution was the key to resolving it.

    Mine had to do specifically with launching the app from TestFlight. It worked fine in Debug, Release/Ad-Hoc but was crashing when creating an AppStore build for TestFlight.

    Here's the thread in case anyone else has something similar:

  • Viswa_007Viswa_007 Member ✭✭

    This is a life saver!!!!

    Found this post in right time, there were lot of uncaught exceptions and not logged to AppCenter !!!

    This solution worked perfectly!!

    Thanks @DanAbramov

Sign In or Register to comment.