IAsyncOperation<StoreProductResult> не содержит определения для GetAwaiter

186
16 июля 2018, 20:40

Есть проект на Xamarin Forms на .net standart 2.0. В общем проекте объявлен интерфейс:

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 standart 2.0

Answer 1

Метод GetAwaiter определен в классе System.WindowsRuntimeSystemExtensions сборки System.Runtime.WindowsRuntime.

Проверьте что у вас подключена эта сборка и что в начале файла есть директива using System;

READ ALSO
C#, MDI и его процесс загрузки

C#, MDI и его процесс загрузки

Есть родительская форма EditData, и дочерняя форма DataClassКак только открываю дочернюю форму там идет выгрузка данные с MS SQL в DataGridView, очень долго...

228
WPF в С# проблема с custom

WPF в С# проблема с custom

Есть код XAML и есть класс CustomVisualFrameworkElement, который унаследован от FrameworkElement и реализует с помощью Visual некоторые фигурыНо XAML почему то не видит...

163
Unity экземпляры класса и ссылки на объекты

Unity экземпляры класса и ссылки на объекты

Возник один вопрос по игровому движку UnityДопустим я хочу создать экземпляр класса Camera

158