IAsyncOperation<IReadOnlyList>"<UserNotification>不包含"GetAwaiter"的定义



我使用的是Visual Studio 2017 Professional。

我一直遵循本指南:https://learn.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"的定义,也找不到接受'IAsyncOperation<IReadOnlyList<UserNotification>>'类型的第一个参数的扩展方法"GetAwaite"(是否缺少"System"的using指令?)

我已经尝试了所有我能在网上找到的东西,从添加引用到:

  • C:\Program Files(x86)\Reference Assemblys\Microsoft\Framework.NETCore\v4.5\SystemRuntime.WindowsRuntime.dll
  • C: \Program Files(x86)\Windows Kits\10\UnionMetadata\Facade\Windows.WinMD

添加NuGet包:

  • UwpDesktop
  • Microsoft.NETCore.UniversalWindowsPlatform

重新安装VS并尝试不同版本的SDK。

我真的不知道是什么导致了这个问题,如果能给我任何正确的指导,我将不胜感激。

您应该添加

using System.WindowsRuntimeSystemExtensions;

它来自System.Runtime.WindowsRuntime程序集,并持有一个具有GetAwaiter扩展名的类。

最新更新