Working around admob crash in Windows Phone apps

As we mentioned earlier in our post, we have been trying out different ad providers for our windows phone apps. One of them being adMob from Google. We found that recent updates of adMob SDK for windows phone (version 4.0.4)  has fixed a couple of issues that were previously being encountered. One of the major one that got improved is the issue of apps getting hung (not responding) due to adMob advertisments. Working with latest SDK, we found apps to be more responsive when ads from adMob were being shown.

Below is the changelog of these latest updates:

Google AdMob Ads SDK for Windows Phone 7 Change Log
========================================
4.0.4
- Fixed ad click bug
- Fixed stealing focus on reload bug
- Ads being reloaded stay available until new ad is available
========================================
4.0.3
- Moved more work off of the UI thread to make apps more responsive
- Fixed IsEnabled flag being ignored
- Refresh rate now respected when there's no fill
========================================

So far so good, so we went ahead and used adMob in our app’s beta release for our beta testers. Soon after, we got reports of crashes from our test team, when returning back to app after ad is clicked

We investigated and found the following callstack

NullReferenceException
at Google.AdMob.Ads.WindowsPhone7.Support.DownloadHelper.<>c__DisplayClass1.b__0(IAsyncResult AsyncResult) 
at System.Net.Browser.ClientHttpWebRequest.<>c__DisplayClassa.b__8(Object state2) 
at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state) 
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
at System.Threading.ThreadPool.WorkItem.doWork(Object o) at System.Threading.Timer.ring()

This issue was reported in google’s support forum, but no solution has been given so far. Woops! Seemed like we can’t integrate adMob in our released apps to users.

But then we thought that we can probably just workaround this by ignoring this exception and preventing our app from crashing (as that is most important, even if adMob doesn’t work after this ignoring and continuing)

So how do we do it? It is pretty simple. We added the following lines of code in our apps’ App.xaml.cs inside Application_UnhandledException

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
  if (e.ExceptionObject.StackTrace.IndexOf("Google") >= 0)
  {
    e.Handled = true; //ignore google admob control exceptions
  }
}

That’s it, and now our apps will ignore all the exceptions that may occur due to Google AdMob control. If you want, you can instead add a more specific exclusion instead of “Google”.

After this, we have not seen any crashes happening in our apps due to adMob. What’s more, adMob continues to work normally, even after this exception gets thrown and is ignored inside Application_UnhandledException.

Let us know if you find this workaround useful. :)

Note: Following exception was being reported earlier and was fixed by Google adMob teams from the server side. Hope that Google will also fix the NullReferenceException  soon.

An unknown error has occurred. Error: 80020101.

About the author

Kanishk Kunal

Kanishk is a Software Engineer turned Online Entrepreneur who has created many successful apps and websites. He devotes most of his time punching his keyboard and swiping his smartphone. Follow him on Twitter @kanishkkunal

2 comments

  1. abdullah tahan says:

    i’m really glade, my app worked now , but no adds shown there :) I’m using WP8 ,
    eventhuow I’ve been using pubcenter.microsoft.com but suddenly all the ads goon in my apps !!

  2. maskaravivek says:

    admob is now in beta for windows phone 8. one can use it on their windows phone app following this tutorial http://www.windowsapptutorials.com/windows-phone/advertising/how-to-use-google-admob-in-windows-phone-app/

Leave a Reply

Your email address will not be published. Required fields are marked *