Hi there,
I´m trying to implement a in-app-purchase-functionality and get an exception when I´m calling RequestProductPurchaseAsync. It states:
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.<BuyFeature>d__7.MoveNext()
That´s what I´m doing:
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.");
}
}
Whenever I call BuyFeature it throws the exception. Except if I call it right in LoadInAppPurchaseProxyFileAsync. Then it seems to be the same thread.
If I replace Task with void in both Methods it doesn´t work either.
Does anybody have an idea what I’m doing wrong?
Thank you,
Harry