WP8 AdMob issue: can't create AdView outside GamePage class

I’m messing with AdMob for WP8 and just realized that I cannot create AdView outside the GamePage class. If I do that, an error will pop up:
System.UnauthorizedAccessException was unhandled by user code

Detail message says it is an “Invalid cross-thread access”.

I googled and found this post: http://stackoverflow.com/questions/13605166/windows-phone-8-threading-invalid-cross-thread-access It seems that the UI thread is a different one from the MonoGame thread.

I also tried handling ads inside the GamePage class instead of my custom adsAgent class, but it seems the UI thread doesn’t have network access. The same error also exists in the official AdMob WP8 examples.

Now I have no idea how to proceed with AdMob WP8 integration… :frowning:

do it like this here

Deployment.Current.Dispatcher.BeginInvoke(() =>
{
    try
    {
        interstitialAd.ShowAd();
     }
     catch (Exception ex)
    {
      Debug.WriteLine(ex.Message);
   }
});

Thanks man! But how do I create an adview instance inside my custom ads agent class constructor? Apparently I cannot do that inside Dispatcher.BeginInvoke()…

I tried this method inside the constructor and it worked. Thanks man!

But there came another issue: the game cannot receive any ad because of a “NetworkError”. I basically copied and pasted the admob wp8 example code and modified it slightly, and apparently this bug exists in the admob examples.

Has anyone been able to make admob work on wp8?

check your Capabilities in your WMAppManifest.XML here

the Example works for me, but only once. If i call interstitialAd.ShowAd(); more than once it crashes.

That’s really weird… I re-downloaded the admob example, put in my ad unit ID and that network error is still there, on both wp device and emulator.

On the other hand, admob iOS has been working pretty well for me though.

Now I really don’t know what to do with admob wp8… :frowning: