IAsyncOperation<IReadOnlyList <UserNotification >> 'не содержит определения для "GetAwaiter"
Я использую Visual Studio 2017 Professional.
Я следовал этому руководству: https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/notification-listener
Мой код проблемы выглядит следующим образом:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Windows.UI.Notifications;
using System;
namespace SeleniumWebChat.Utilities
{
// This class handles Windows 'Toast' notifications that pop up when a new webchat/call is received
static class WinNotificationHandler
{
static async Task<bool> TaskCheckWinNotification(string notifType, string guest)
{
Windows.UI.Notifications.Management.UserNotificationListener listener = Windows.UI.Notifications.Management.UserNotificationListener.Current;
//only read notifications if we have access - this may need to be set in windows settings
if (listener.GetAccessStatus().ToString() == "Allowed")
{
// Get the windows toast notifications as a list
IReadOnlyList<UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);
//Console.Error.WriteLine("number of notifications found: " + notifs.Count());
}
return false;
}
}
}
Проблема в этой строке:
IReadOnlyList<UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);
Который дает ошибку:
'IAsyncOperation<IReadOnlyList<UserNotification>>'
не содержит определения для GetAwaiter и метода расширения GetAwaiter, принимающего первый аргумент типа'IAsyncOperation<IReadOnlyList<UserNotification>>'
может быть найдено (вам не хватает директивы using для 'System'?)
Я перепробовал все, что могу найти в Интернете, от добавления ссылок на:
- C: \ Program Files (x86) \ Справочные сборки \ Microsoft \ Framework.NETCore \ v4.5 \ System.Runtime.WindowsRuntime.dll
- C: \ Program Files (x86) \ Windows Kits \ 10 \ UnionMetadata \ Facade \ Windows.WinMD
Чтобы добавить пакеты NuGet:
- UwpDesktop
- Microsoft.NETCore.UniversalWindowsPlatform
Переустанавливать VS и пробовать разные версии SDK.
Я действительно понятия не имею, что вызывает эту проблему, я был бы очень благодарен за любые указатели в правильном направлении.
1 ответ
Вы должны добавить
using System.WindowsRuntimeSystemExtensions;
это из сборки System.Runtime.WindowsRuntime и содержит класс с расширениями GetAwaiter.