AggregateException when invoke UI Thread in windows Phone 8.1. Crashes only from windows store

Hello,
I have a strange problem with my game for windows phone 8.1. I’ve integrated the vserv sdk for windows 8.1. I implemented the ads caching and showing in the App.xaml.cs in Visual Studio because it was the only way to get them working. First I tried to call the VServ’s cache ad method directly but I got the following exception:

Exception: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
at Windows.UI.Xaml.Controls.ProgressRing…ctor()
at com.vserv.windows.ads.wp81.VservAdView.InstantiateProgressRing()
at com.vserv.windows.ads.wp81.VservAdView.CacheAd()
at Template.App.SendShowAdMessage_showAdEvent()
at SendShowAdMessage.sendShowAdMessage()
at PresentAnimation.OnPresentPressed()
at PresentAnimation.$Invoke4(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)

Then I changed the code like this to resolve the problems with the different threads:
appCallbacks.InvokeOnUIThread(new AppCallbackItem(() =>
{

adView.CacheAd();

}), false);

The full code is:
void initVServ()
{
if (!Configuration.adsRemoved())
{
Debug.WriteLine(“Ads Are not removed.”);

adView = new VservAdView();
adView.UX = VservAdUX.Interstitial;
adView.ZoneId = “XXXXXXXXXXX”;
//adView.TestDevice = new List() { “” };
adView.TimeOut = 10;
adView.RequestedOrientation = RequestedOrientation.Landscape;
isAdCached = false;

adView.DidCacheAd += adView_DidCacheAd;
adView.FailedToCacheAd += adView_FailedToCacheAd;

//adView.CacheAd();

SendShowAdMessage.showAdEvent += SendShowAdMessage_showAdEvent;
}
}

void SendShowAdMessage_showAdEvent()
{
if (!Configuration.adsRemoved())
{
/appCallbacks.InvokeOnUIThread(new AppCallbackItem(() =>
{
adView.LoadAd();
}), true);
/

if (isAdCached)
{
appCallbacks.InvokeOnUIThread(new AppCallbackItem(() =>
{
adView.ShowAd();
adView.CacheAd();
}), false);
}
else
{
appCallbacks.InvokeOnUIThread(new AppCallbackItem(() =>
{
try
{
adView.CacheAd();
}
catch (System.Exception e)
{
Debug.WriteLine(e.StackTrace);
Debug.WriteLine(e.Message);
}

}), false);
}

}

}

void adView_FailedToCacheAd(object sender, EventArgs e)
{
Debug.WriteLine(“Failed to Cache Ad - VServ”);
//adView.CacheAd();
isAdCached = false;
}

void adView_DidCacheAd(object sender, EventArgs e)
{
Debug.WriteLine(“Ad Cached - VServ”);
isAdCached = true;

}

Everything worked well that way except that I get AggregateException after the game returned from the UI thread and the cacheAd callback methods are called. When I sideload the app from visual studio there are no crashes because of this but after I download it from the windows phone store as beta app it crashes when I call the cacheAd method. I removed the VServ SDK, uploaded the game again and this time it doesn’t crashed. I wonder if there is something that I missed about the way I handle the thread changes. What could be the reason for the game to crash only when it’s downloaded from the store?

Thanks in advance!

Well, the error is pretty self explanatory:

Exception: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

SendShowAdMessage.sendShowAdMessage() calls into the plugin from the wrong thread it seems.

What I should do to call the methods in App.xaml.cs in the right thread?

It’s not the file that matters. I think you should call it from UI thread.
You can do this via AppCallbacks class or via Dispatcher, whichever is easier to access for you.

I’m using :
appCallbacks.InvokeOnUIThread(new AppCallbackItem(() =>
{
try
{
adView.CacheAd();
}
catch (System.Exception e)
{
Debug.WriteLine(e.StackTrace);
Debug.WriteLine(e.Message);
}

}), false);

But the aggregate exception and crashes when downloaded from store still exists.

Are you creating the asView itself on UI thread?

Yes I do. I create it after the splash screen gets removed.

Simply enable exceptions via Debug->Exceptions, and when this exception popsup, check the callstack.

Hello stamenkrumov, i cant help u but you can help me, can u plz tell me how to implement admob in our own app? and how to call it when level complete or level fail… ?? i would be very helpful for me