IAsyncOperation<IReadOnlyList<UserNotification>>' does not contain a definition for 'GetAwaiter' [duplicate]

不想你离开。 提交于 2020-05-15 05:19:04

问题


I am using Visual Studio 2017 Professional.

I have been following this guide: https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/notification-listener

My problem code is as follows:

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;
        }
    }
}

The problem is with this line:

IReadOnlyList<UserNotification> notifs = await listener.GetNotificationsAsync(NotificationKinds.Toast);

Which gives the error:

'IAsyncOperation<IReadOnlyList<UserNotification>>' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation<IReadOnlyList<UserNotification>>' could be found (are you missing a using directive for 'System'?)

I've tried everything I can find online, from adding references to:

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

To adding NuGet packages:

  • UwpDesktop
  • Microsoft.NETCore.UniversalWindowsPlatform

To reinstalling VS and trying different versions of the SDK.

I really have no idea what is causing this issue, I would be very grateful for any pointers in the right direction.


回答1:


You should add

 using System.WindowsRuntimeSystemExtensions;

this is from the System.Runtime.WindowsRuntime assembly and holds a class with the GetAwaiter extensions.



来源:https://stackoverflow.com/questions/54515716/iasyncoperationireadonlylistusernotification-does-not-contain-a-definition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!