.net 标准 2.0 上有一个关于 Xamarin Forms 的项目。在通用项目中声明了一个接口:
public interface IIAPService
{
Task<string> GetAppInfoAsync();
}
在 UWP 项目中实施时(取自 Microsoft 网站的示例:
public class IAPService : IIAPService
{
private StoreContext context = null;
public IAPService() { }
public async Task<string> GetAppInfoAsync()
{
if (context == null)
{
context = StoreContext.GetDefault();
// If your app is a desktop app that uses the Desktop Bridge, you
// may need additional code to configure the StoreContext object.
// For more info, see https://aka.ms/storecontext-for-desktop.
}
// Get app store product details. Because this might take several moments,
// display a ProgressRing during the operation.
StoreProductResult queryResult = await context.GetStoreProductForCurrentAppAsync();
if (queryResult.Product == null)
{
// The Store catalog returned an unexpected result.
//textBlock.Text = "Something went wrong, and the product was not returned.";
// Show additional error info if it is available.
if (queryResult.ExtendedError != null)
{
//textBlock.Text += $"\nExtendedError: {queryResult.ExtendedError.Message}";
}
return;
}
// Display the price of the app.
//textBlock.Text = $"The price of this app is: {queryResult.Product.Price.FormattedBasePrice}";
}
}
一个错误:Ошибка CS4036 'IAsyncOperation<StoreProductResult>" не содержит определения для "GetAwaiter", и не удалось найти метод расширения "GetAwaiter", принимающий тип "IAsyncOperation<StoreProductResult>" в качестве первого аргумента (возможно, пропущена директива using для "System").
在 Google 的帮助下,我只找到了一个解决方案:使用 .net framework 4.5 而不是 4.0,但问题是我使用的是 .net standard 2.0
该方法
GetAwaiter在System.WindowsRuntimeSystemExtensions程序集类中定义System.Runtime.WindowsRuntime。检查您是否已连接此程序集并且文件开头是否有指令
using System;