Metro Nuggets

Bitesized tidbits for building Modern (Metro) apps.

Tip: Nokia Ad Exchange (NAX) and Annoying Unhandled Exceptions

One of the ways in which developers try to increase their revenue is to include ads within their app and there are a number of different providers, from Google to Microsoft to Nokia. All seem to have one thing in common: Unhandled Exceptions. For some reason, ad controls seem to be some of the biggest culprits for unhandled exceptions in apps, and better still, there’s nothing you can do to actually handle them. Nothing. Not. A. Damn. Thing! So how do you stop your app from sinking without a trace in a barrage of error reports? Nothing elegant, I can tell you that, but it works.

The Solution

As mentioned, this isn’t elegant, it’s very hacky and I really shouldn’t need to be doing this, but here I am. Although this post deals with the Nokia Ad Exchange control, the same thing could be done for all the offending blighters, you could even wrap it up if you use all of them (say if you use Unified Ad Control or AdRotator)

So what do we need? Well, I’ll show you my UnhandledException event handler

        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
            // I'm not logging the Nokia Ad Exchange's shitty exceptions
            if (e.ExceptionObject.StackTrace.Contains("Inneractive.Ad.InneractiveAdControl")) 
                e.Handled = true;
            if (Debugger.IsAttached)
                // An unhandled exception has occurred; break into the debugger

That’s how I’m dealing with them. You may have extra code after the Debugger section, if that’s the case, you may end up being best to set e.Handled = true before you check whether the exception is one from Inneractive (Nokia).

Like I said, it’s not pretty, and I’ll be honest, I’m not entirely sure if this will prevent your crash numbers in the Dev Centre from going up, but it will at least prevent your app from appearing unstable when it’s not your fault (for once), and also prevents you from getting crash reports that are just ad control funk ups.

As a PS, the exceptions I was getting, I have emailed to Inneractive support, so hopefully a future update will cure my problems.


4 responses to “Tip: Nokia Ad Exchange (NAX) and Annoying Unhandled Exceptions

  1. Philip Colmer June 14, 2013 at 10:39

    Thank you! This was driving me bonkers.

    • scottisafool June 14, 2013 at 10:41

      Yeah, the worst part was it constantly hitting the break point when debugging too. In the end I had to do something.

  2. Pingback: Tip: Nokia Ad Exchange (NAX) and Annoying Unhandled Exceptions

  3. Matt Lacey June 14, 2013 at 15:54

    AFAIK this won’t impact what gets reported in the dev centre as that is a summarized version of everything that hits the unhandled exception handler, or would, if you remove it.
    I’d recommend testing this approach carefully and be aware that it might not catch every exception from 3rd party controls, especially if they use any non-managed code.

Leave a Reply to Philip Colmer Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: