This project is read-only.

Runtime Exception

Nov 24, 2013 at 11:19 AM
I'm trying to use the Alpha version of AdRotator but I keep getting a Runtime exception when I launch the app in debug. I'm targeting Windows 8.1 SDK.

Currently I've entered details only for AdDuplex and PubCenter. My config file is this:
<?xml version="1.0" encoding="utf-8"?>
<AdSettings xmlns:xsi="" xmlns:xsd="">
        <AdCultureDescriptor CultureName="default">
          <Probabilities Probability="50" AdType="PubCenter" AppID="96eb6d5c-c9b4-47f1-99b8-c4bf1d4f1e08" SecondaryID="10327205" />
          <Probabilities Probability="50" AdType="AdDuplex" AppID="57807"/>
When I launch my app, I get this exception:
   at AdRotator.Model.AdSettingsExtensions.<>c__DisplayClass4.<GetAdDescriptorBasedOnUICulture>b__1(AdCultureDescriptor x)
   at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at AdRotator.Model.AdSettingsExtensions.GetAdDescriptorBasedOnUICulture(AdSettings adsettings, String culture)
   at AdRotator.AdRotatorComponent.<GetConfig>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__4(Object state)
   at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
I've added both PubCenter and AdDuplex references but no other Ad SDKs.
Am I missing something here ?

Nov 24, 2013 at 1:47 PM
Edited Nov 24, 2013 at 1:59 PM
Ok, after investigating it's a very easy solution.
You are using V1 configuration with the new V2 project.
But it shouldn't crash the control by having invalid XML, so we will need to resolve that in the upcoming update.

You config should really be as follows:
<?xml version="1.0" encoding="utf-8"?>
<AdSettings xmlns:xsi="" xmlns:xsd="">
    <CultureDescriptors CultureName="">
    <AdDuplex AppId="57807" Probability="50"/>
    <PubCenter AppId="96eb6d5c-c9b4-47f1-99b8-c4bf1d4f1e08" SecondaryId="10327205" Probability="50"/>
Hope this helps

I've also noticed a gap in the instructions while reviewing your issues. Because PubCenter is a WinMD file, you need to pass your pubcenter reference to AdRotator in order to show them, just add the following line in the page constructor for it to work:
        public MainPage()
            //Note - provided you named your control on the XAML page Win8AdRotator. Don't use the name AdRotator as it's reserved
            Win8AdRotator.PlatformAdProviderComponents.Add(AdRotator.Model.AdType.PubCenter, typeof(Microsoft.Advertising.WinRT.UI.AdControl));
Then PubCentre Ads will work as well in Windows 8 (not needed for Windows Phone releases)
Nov 25, 2013 at 10:35 PM
Hi Darkside, thank you for the very quick response! I've been busy lately but tomorrow I'll update my code with your fixes.

Dec 1, 2013 at 1:25 PM
Edited Dec 1, 2013 at 1:37 PM
I've finally been able to test the code and now it works, no more Runtime exceptions!
Now I have another issue: if I use only AdDuplex in my configuration, everything works just fine, but if I use also PubCenter provider, the rotator stops serving ads. I've tried with different probabilities but the result is the same, as soon as the app starts, nothing is displayed (except the initial AdDuplex banner for a fraction of second).
I've also tried put the regular AdControl with the same AppId and AdUnitId but except for only a single time, I keep getting "No Ads to serve".
I'm not so worried about PubCenter not having ads for my app, what puzzles me is why the whole AdRotator stops from working it that happens.

This is the output I get when I listen to AdRotator debug event with only AdDuplex enabled:

Trying provider AdDuplex
Ad created for provider AdDuplex
Ad created for provider AdDuplex
--- some framework related trace ---
Ad failed request for: AdDuplex
Ads failed request for: AdDuplex
Trying provider None
No Ads available

(Even though it reports failures, regular AdDuplex ad are shown).

This is the output I get when only PubCenter is active:

Trying provider PubCenter
Ad created for provider PubCenter
Ad created for provider PubCenter

No ads are shown and nothing else appears in outpout

Dec 3, 2013 at 5:28 PM
Sounds like your project is working fine.
We find that PubCenter will not produce ads unless you are in the US, there are the test Ad Units but MS keep moving the documentation around those.

If you have both PubCenter and AdDuplex configured with percentages (even if the AdDUplex one is very low, say 5%) then if PubCenter fails to get an Ad, then AdDUplex ads will show.