18

I found a few scattered responses to similar problems (mostly with Windows Phone 7) but wanted to post an answer that contained all requirements for Windows Phone 8 Ads.

I've been having some issues setting an ad up in Windows Phone 8. Every time I ran the emulator I ran into an issue where the app would run but the ad would not show up.

The app ran properly but I noticed in the output console that the following exception was logged:

An exception of type 'Microsoft.Advertising.Shared.AdException' occurred in Microsoft.Advertising.Mobile.DLL and wasn't handled before a managed/native boundary

Ads show up fine in one app I am developing but not another and the exception does not show any helpful information.

ellemayo
  • 3,218
  • 2
  • 18
  • 30

1 Answers1

49

I figured out how to catch the exception and see what the issue actually was (which was a large amount of missing capabilities in my Manifest file). In order to try and catch the exception from the AdControl and get the data I needed, I added the following to my page.

Catch Ad Control Errors

    public MainPage()
    {
        InitializeComponent();

        AdUnit.ErrorOccurred += AdUnit_ErrorOccurred;
    }

    void AdUnit_ErrorOccurred(object sender, Microsoft.Advertising.AdErrorEventArgs e)
    {
        throw new NotImplementedException();
    }

Which showed me that I was missing the MEDIALIB permission and the PHONEDIALER permission. I ran some testing and determined that any app that runs ads will require the following permissions:

Required Permissions

ID_CAP_IDENTIFY_USER
ID_CAP_MEDIALIB_PHOTO
ID_CAP_NETWORKING
ID_CAP_PHONEDIALER
ID_CAP_WEBBROWSERCOMPONENT

Set Parameters

From other posts I've read it is also important to make sure you set your ad units width/height properly to 480/80, if it is auto and doesn't have the minimum demensions then the ad will not show.

Make sure that to view it in the emulator you can only use test ApplicationId and AdUnitId. PubCenter credentials will only work in a published application.

<UI:AdControl x:Name="AdUnit" Height="80" Width="480"
    AdUnitId="Image480_80" ApplicationId="test_client" />

Hide or Swap Failed/Empty Ad Controls

If your AdControl fails it leaves a big empty space in your ad. You can either hide it or swap it with an ad from another network. To do this, catch the exception as shown above (AdUnit_ErrorOccurred) and added the following:

To Hide:

AdUnit.Height = 0;
AdUnit.Visibility = System.Windows.Visibility.Collapsed;

Setting the visibility didn't work on its own, the height has to be set to 0 as well.

Swap Ad:

Instead of hiding the AdControl, you could show an alternate ad bar from a service like http://www.adduplex.com.

ellemayo
  • 3,218
  • 2
  • 18
  • 30
  • I followed your guidelines and the add unit worked. However, now when I submitted it to marketplace (still in signing process) under details I can see "Add units - none" which worries me a bit. Is that normal? – Booyaches Mar 05 '13 at 22:44
  • 1
    @Booyaches I believe that is for the ad units that you have setup using the optional "Add in-app advertising" step when submitting your app. This step doesn't seem to be enabled for existing pubCenter accounts yet, so most people can't use it. Your ads should still display fine, if possible test it on an actual device to be sure your settings are correct. – ellemayo Mar 06 '13 at 14:34
  • @ellemayo Hi can you tell how much an ad take to show on a page ? – loop Oct 04 '14 at 15:54
  • @loop how long for it to show up? Shouldn't take more than a second or 2 once it's setup... use the test ad to make sure it's setup correctly and that should show up even faster. – ellemayo Oct 07 '14 at 15:20
  • @ellemayo Actually Everything is setup, I just exploring on which page it is better to show the add.. so that it is count as impression. – loop Oct 07 '14 at 15:41