title: RequestProductPurchaseAsync throws “Cannot change thread mode after it is set”
body: <p>I'm using monogame as a framework for games and I'm trying to implement a in-app-purchase-functionality in an UWP-App which throws an exception when I'm calling <code>RequestProductPurchaseAsync</code>. It states:</p>
  
  <blockquote>
    <p>Cannot change thread mode after it is set. (Exception from HRESULT:
    0x80010106 (RPC_E_CHANGED_MODE))  at
    Windows.ApplicationModel.Store.CurrentAppSimulator.RequestProductPurchaseAsync(String
    productId)  at
    Crocs_World__Xbox_Edition_.App.d__7.MoveNext()</p>
  </blockquote>
  
  <p>That's what I'm doing in code:</p>
  
  <pre><code>public async Task LoadInAppPurchaseProxyFileAsync()   
  {
       StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("data");
       StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-purchase.xml");
       licenseChangeHandler = new LicenseChangedEventHandler(InAppPurchaseRefreshScenario);
       CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler;
       await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);
  
      // setup application upsell message
      try
      {
          ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync();
          var product1 = listing.ProductListings["product1"];
          var product2 = listing.ProductListings["product2"];               
      }
      catch (Exception e)
      {
          Debug.WriteLine("LoadListingInformationAsync API call failed:" + e);               
      }
  }
  
  private async void InAppPurchaseRefreshScenario()
  {           
      Debug.WriteLine("InAppPurchaseRefreshScenario");
  }
  
  public async Task BuyFeature()
  {
      LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;
      if (!licenseInformation.ProductLicenses["product2"].IsActive)
      {
          Debug.WriteLine("Buying Product 2...");
          try
          {
              await CurrentAppSimulator.RequestProductPurchaseAsync("product2");
              if (licenseInformation.ProductLicenses["product2"].IsActive)
              {
                  Debug.WriteLine("You bought Product 2.");
              }
              else
              {
                  Debug.WriteLine("Product 2 was not purchased.");
              }
          }
          catch (Exception e)
          {
              Debug.WriteLine("Unable to buy Product 2." + e);
          }
      }
      else
      {
          Debug.WriteLine("You already own Product 2.");
      }
  }
  </code></pre>
  
  <p>Whenever I call <code>BuyFeature</code> it throws the exception. Except if I call it right in <code>LoadInAppPurchaseProxyFileAsync</code>. Then it seems to be in the same thread I guess.
  If I replace <code>Task</code> with <code>void</code> in both methods it doesn't work either. It also doesn't matter if I call it from app.xaml.cs or the game.cs.
  Does anybody have an idea what I'm doing wrong?</p>
  
  <p>Thank you,</p>
  
  <p>Harry </p>