'System.NullReferenceException' occurred in Inneractive.Nokia.Ad.dll

Mar 29, 2013 at 1:49 PM
I am trying to create a WP Unified Adcontrol from C# instead of XAML, but when I set the FallbackAdProviderName or the InitialAdProvider to "InnerActive" I get the following error:
A first chance exception of type 'System.NullReferenceException' occurred in Inneractive.Nokia.Ad.dll.

Below you can find my C# code as well as my AdSettings.xml
C#-code:
MC.Phone.Ads.AdControl unifiedAdControl = new MC.Phone.Ads.AdControl();

            MC.Phone.Ads.PubCenter.PubCenterAdProvider pubCenterAdProvder = new MC.Phone.Ads.PubCenter.PubCenterAdProvider();
            pubCenterAdProvder.AdUnit = "";
            pubCenterAdProvder.Application = "";

            MC.Phone.Ads.InnerActive.InnerActiveAdProvider inneractiveProvider = new MC.Phone.Ads.InnerActive.InnerActiveAdProvider();
            inneractiveProvider.App = "";

            MC.Phone.Ads.AdDuplex.AdDuplexAdProvider adDuplexProvider = new MC.Phone.Ads.AdDuplex.AdDuplexAdProvider();
            adDuplexProvider.App = "";

            MC.Phone.Ads.Smaato.SmaatoAdProvider smaatoProvider = new MC.Phone.Ads.Smaato.SmaatoAdProvider();
            smaatoProvider.AdSpace = ;
            smaatoProvider.Publisher = ;

            unifiedAdControl.AdProviders.Add(pubCenterAdProvder);
            unifiedAdControl.AdProviders.Add(adDuplexProvider);
            unifiedAdControl.AdProviders.Add(smaatoProvider);
            unifiedAdControl.AdProviders.Add(inneractiveProvider);

            unifiedAdControl.FallbackAdProviderName = "InnerActive";
            unifiedAdControl.ProvideCountry = MC.Phone.Ads.ProvideCountry.FromCulture;

            MC.Phone.Ads.Strategy.RemoteAdProviderStrategy remoteStrategy = new MC.Phone.Ads.Strategy.RemoteAdProviderStrategy();
            remoteStrategy.LocalProviderSettingsUri = new Uri("/Ads/AdSettings.xml", UriKind.Relative);
            remoteStrategy.RemoteProviderSettingsUri = new Uri("http://frankwin.fmtcfaber.nl/wpad/AdSettingsWpPenguinsMemory.xml");
            remoteStrategy.WhenOffline = MC.Phone.Ads.Strategy.WhenOffline.NoAds;

            unifiedAdControl.AdProviderStrategy = remoteStrategy;

            unifiedAdControl.IsTest = false;
AdSettings.xml:
<?xml version="1.0" encoding="utf-8" ?>
<AdSettings xmlns="http://wpunifiedad.codeplex.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wpunifiedad.codeplex.com UnifiedAd.xsd">
  <CountryDescriptors>
    <AdCountryDescriptor InitialAdProvider="InnerActive">
      <Probability Value="20" AdProvider="InnerActive" />
      <Probability Value="20" AdProvider="Smaato" />
      <Probability Value="10" AdProvider="AdDuplex" />
      <Probability Value="50" AdProvider="PubCenter" />
    </AdCountryDescriptor>  
  </CountryDescriptors>
</AdSettings>
I hope someone can figure out what I am doing from. When setting the values for the XAML version I do not get the exception, so there must be some C# code I am missing.
Coordinator
Mar 29, 2013 at 2:00 PM
Do you have the full stacktrace of the NullReferenceException?
Mar 29, 2013 at 2:02 PM
System.NullReferenceException occurred
Message=NullReferenceException
StackTrace:
   at Inneractive.Nokia.Ad.InneractiveAd.GetOptionalParamsStr(Dictionary`2 optionalParams)
   at Inneractive.Nokia.Ad.InneractiveAd.DisplayAd(String appId, IaAdType adType, Grid rootGrid, Int32 reloadTime, Dictionary`2 optionalParams)
   at MC.Phone.Ads.InnerActive.InnerActiveAdProvider.ProvideAd()
   at MC.Phone.Ads.AdControl.<ProvideAd>b__b(IAdProvider provider)
   at Microsoft.Phone.Reactive.AnonymousObserver`1.Next(IAdProvider value)
   at Microsoft.Phone.Reactive.AbstractObserver`1.OnNext(IAdProvider value)
   at Microsoft.Phone.Reactive.AnonymousObservable`1.AutoDetachObserver.Next(IAdProvider value)
   at Microsoft.Phone.Reactive.AbstractObserver`1.OnNext(IAdProvider value)
   at Microsoft.Phone.Reactive.Observable.<>c__DisplayClass147`1.<>c__DisplayClass149.<>c__DisplayClass14b.<ObserveOn>b__142(Object _)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at System.Delegate.DynamicInvokeOne(Object[] args)
   at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
   at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
   at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
   at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
   at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)
Coordinator
Mar 29, 2013 at 2:13 PM
Can you try to explicitly set the CountryCode on the InnerActiveAdProvider to say "en-US" ?

The CountryCode field should be following the Current Culture, but maybe that's causing the problem. It's the only property that could cause a problem in the "GetOptionalParamsStr" I think.
Mar 29, 2013 at 2:28 PM
Added it, but am still getting:
System.NullReferenceException occurred
Message=NullReferenceException
StackTrace:
   at Inneractive.Nokia.Ad.InneractiveAd.GetOptionalParamsStr(Dictionary`2 optionalParams)
   at Inneractive.Nokia.Ad.InneractiveAd.DisplayAd(String appId, IaAdType adType, Grid rootGrid, Int32 reloadTime, Dictionary`2 optionalParams)
   at MC.Phone.Ads.InnerActive.InnerActiveAdProvider.ProvideAd()
   at MC.Phone.Ads.AdControl.<ProvideAd>b__b(IAdProvider provider)
   at Microsoft.Phone.Reactive.AnonymousObserver`1.Next(IAdProvider value)
   at Microsoft.Phone.Reactive.AbstractObserver`1.OnNext(IAdProvider value)
   at Microsoft.Phone.Reactive.AnonymousObservable`1.AutoDetachObserver.Next(IAdProvider value)
   at Microsoft.Phone.Reactive.AbstractObserver`1.OnNext(IAdProvider value)
   at Microsoft.Phone.Reactive.Observable.<>c__DisplayClass147`1.<>c__DisplayClass149.<>c__DisplayClass14b.<ObserveOn>b__142(Object _)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at System.Delegate.DynamicInvokeOne(Object[] args)
   at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
   at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
   at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
   at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
   at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)
Mar 29, 2013 at 5:15 PM
Seems to go ok in other cases when I use Smaato / AdDuplex or PubCenter as FallbackAdProviderName / InitialAdProvider.

Although...just found a new case that goes wrong. FallBackAdProviderName = "PubCenter" and AdSettings look like:
<?xml version="1.0" encoding="utf-8" ?>
<AdSettings xmlns="http://wpunifiedad.codeplex.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wpunifiedad.codeplex.com UnifiedAd.xsd">
  <CountryDescriptors>
    <AdCountryDescriptor InitialAdProvider="PubCenter">
      <Probability Value="20" AdProvider="InnerActive" />
      <!--Probability Value="20" AdProvider="Smaato" />
      <Probability Value="10" AdProvider="AdDuplex" /-->
      <Probability Value="50" AdProvider="PubCenter" />
    </AdCountryDescriptor>  
  </CountryDescriptors>
</AdSettings>
Giver error: System.NullReferenceException occurred
Message=NullReferenceException
StackTrace:
   at Inneractive.Nokia.Ad.InneractiveAd.GetOptionalParamsStr(Dictionary`2 optionalParams)
   at Inneractive.Nokia.Ad.InneractiveAd.DisplayAd(String appId, IaAdType adType, Grid rootGrid, Int32 reloadTime, Dictionary`2 optionalParams)
   at MC.Phone.Ads.InnerActive.InnerActiveAdProvider.ProvideAd()
   at MC.Phone.Ads.AdControl.<ProvideAd>b__b(IAdProvider provider)
   at Microsoft.Phone.Reactive.AnonymousObserver`1.Next(IAdProvider value)
   at Microsoft.Phone.Reactive.AbstractObserver`1.OnNext(IAdProvider value)
   at Microsoft.Phone.Reactive.AnonymousObservable`1.AutoDetachObserver.Next(IAdProvider value)
   at Microsoft.Phone.Reactive.AbstractObserver`1.OnNext(IAdProvider value)
   at Microsoft.Phone.Reactive.Observable.<>c__DisplayClass147`1.<>c__DisplayClass149.<>c__DisplayClass14b.<ObserveOn>b__142(Object _)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at System.Delegate.DynamicInvokeOne(Object[] args)
   at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
   at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
   at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
   at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
   at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)
Mar 29, 2013 at 5:53 PM
With the last mentioned AdSettings.xml also the my WP Unified Ad Control XAML-version is crashing......
Mar 29, 2013 at 8:49 PM
Probably found the solution :-)

I have set the FallbackAdProviderName on the ad control itself as well as on the RemoteAdProviderStrategy to the same AdProvider
Now I can set the InitialAdProvider in the AdSettings.xml to any of the AdProviders without getting the NullReferenceException.
Coordinator
Apr 3, 2013 at 6:45 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.