Xamarin Forms iOS Exception Handler, get current exception handler - Dupe from XF RRS feed

  • Question

  • User304518 posted

    So recently we wanted to add New Relic analytic/crash reporter to our Xamarin Forms app (iOS and Android). Our app currently has many analytic and crash reporters all working together. However when integrating New Relic on iOS side, we get an error saying it got replaced as the exception handler: Error: The New Relic exception handler has been replaced. This may result in crashes no longer reporting to New Relic.

    Now i know of the iOS limitation of one handler only (Apple Docs).

    Ive tried removing the other services/libraries and i still get the error and crashes are not reported. Im wondering if its something Xamarin (or App Center SDK, Distribute, Crashes, Analytics) related more as most of these libraries are also used in conjunction with new relic on other apps i hear. So im trying to use NSGetUncaughtExceptionHandler at various points to see when/where/who replaces the New Relic one and work from there. I dont see anything in the Xamarin iOS docs about that method or where/how to use it.

    Ive seen this post, Xamarin Forum Post but dont know how to use it or makes much sense to me.

    Any help with the ios unhandled exeception handler would be greatly appreciated.

    Duplicate from Xamarin Forms Forums: Original Post

    Monday, March 30, 2020 9:27 PM


  • User304518 posted

    Copying my answer from my original question for extra visibility.

    Finally got around to using the NSGetUncaughtExceptionHandler

    private void CheckIOSSystemExceptionHandler() { try { Debug.WriteLine($"Starting ios exception handler checks"); var handler = NSGetUncaughtExceptionHandler(); Dlinfo info; dladdr(handler, out info); var fname = Marshal.PtrToStringAuto(info.dlifname); var sname = Marshal.PtrToStringAuto(info.dli_sname); Debug.WriteLine($"ios exception handler checks result: {handler}\n\tFNAME: {fname}\n\tSNAME: {sname}"); } catch(Exception e) { // do something with excetpion } }

    [DllImport(ObjCRuntime.Constants.FoundationLibrary, EntryPoint = "NSGetUncaughtExceptionHandler")] private static extern IntPtr NSGetUncaughtExceptionHandler();

    [DllImport(ObjCRuntime.Constants.libcLibrary)] internal static extern int dladdr(IntPtr addr, out Dl_info info);

    internal struct Dlinfo { internal IntPtr dlifname; /* Pathname of shared object / internal IntPtr dli_fbase; / Base address of shared object / internal IntPtr dli_sname; / Name of nearest symbol / internal IntPtr dli_saddr; / Address of nearest symbol */ }

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, April 7, 2020 4:03 PM