Windows RequestProductPurchaseAsync抛出平台::InvalidArgumentException^

Windows RequestProductPurchaseAsync抛出平台::InvalidArgumentException^,windows,asynchronous,windows-runtime,in-app-purchase,windows-store-apps,Windows,Asynchronous,Windows Runtime,In App Purchase,Windows Store Apps,我正在尝试应用内购买API(C++/CX)和RequestProductPurchaseAsync抛出一个Platform::InvalidArgumentException^ 我有以下代码: // loading store create_task(CurrentAppSimulator::LoadListingInformationAsync()).then([](ListingInformation^ listing) { auto product1 = listing->P

我正在尝试应用内购买API(C++/CX)和
RequestProductPurchaseAsync
抛出一个
Platform::InvalidArgumentException^

我有以下代码:

// loading store
create_task(CurrentAppSimulator::LoadListingInformationAsync()).then([](ListingInformation^ listing)
{
    auto product1 = listing->ProductListings->Lookup("product1");
    auto product2 = listing->ProductListings->Lookup("product2");
});

//after that finishes I try to purchase product2
auto licenseInformation = CurrentAppSimulator::LicenseInformation;
if (!licenseInformation->ProductLicenses->Lookup("product2")->IsActive)
{
 // this exact next line throws InvalidArgumentException
 auto op = CurrentAppSimulator::RequestProductPurchaseAsync("product2", true); // throws !!!!!
 auto purchaseTask = create_task(op);

 purchaseTask.then([](task<Platform::String^> currentTask)
    {
        ...
    });
}
else ...
//加载存储
创建任务(CurrentAppSimulator::LoadListingInformation同步())。然后([](ListingInformation^列表)
{
自动产品1=列表->产品列表->查找(“产品1”);
自动产品2=列表->产品列表->查找(“产品2”);
});
//完成后,我尝试购买产品2
auto licenseInformation=CurrentAppSimulator::licenseInformation;
如果(!licenseInformation->ProductLicenses->Lookup(“product2”)->IsActive)
{
//下一行将抛出InvalidArgumentException
auto op=CurrentAppSimulator::RequestProductPurchaseAsync(“product2”,true);//抛出!!!!!
自动购买任务=创建任务(op);
purchaseTask.then([](任务当前任务)
{
...
});
}
其他的
如果在Windows应用商店示例项目中使用此代码,则完全相同的代码可以工作,但在我自己的项目中不工作。(显然是使用相同的假冒产品xml文件)


有人能看一下吗?谢谢:)

我找到了解决方案:所有WinRT store函数都必须在UI线程上调用,因此从UI线程获取一个CoreDispatcher,并保留它以通过该线程调用这些函数