Same question as C# Get Current Notification Details | UserNotification
I posted the 2 DLLs to be referenced and it works fine for me with a .NET Framework project
C# How to Use Notification Listener
I'm trying to code a form for show notifications in my form from Notification Center but there is some error I did not understand errors.
Errors:
*Severity Code Description Project File Line Suppression State
Error CS4036 'IAsyncOperation<UserNotificationListenerAccessStatus>' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation<UserNotificationListenerAccessStatus>' could be found (are you missing a using directive for 'System'?) WindowsFormsApp7 C:\Users\stock\source\repos\WindowsFormsApp7\WindowsFormsApp7\Class1.cs 12 Active
*
*Severity Code Description Project File Line Suppression State
Error CS1061 'UserNotificationListener' does not contain a definition for 'GetNotifications' and no accessible extension method 'GetNotifications' accepting a first argument of type 'UserNotificationListener' could be found (are you missing a using directive or an assembly reference?) WindowsFormsApp7 C:\Users\stock\source\repos\WindowsFormsApp7\WindowsFormsApp7\Class1.cs 17 Active
*
*Severity Code Description Project File Line Suppression State
Error CS1061 'UserNotificationChangedEventArgs' does not contain a definition for 'Notification' and no accessible extension method 'Notification' accepting a first argument of type 'UserNotificationChangedEventArgs' could be found (are you missing a using directive or an assembly reference?) WindowsFormsApp7 C:\Users\stock\source\repos\WindowsFormsApp7\WindowsFormsApp7\Class1.cs 33 Active
*
*Severity Code Description Project File Line Suppression State
Error CS4036 'IAsyncOperation<UserNotificationListenerAccessStatus>' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation<UserNotificationListenerAccessStatus>' could be found (are you missing a using directive for 'System'?) WindowsFormsApp7 C:\Users\stock\source\repos\WindowsFormsApp7\WindowsFormsApp7\Form2.cs 29 Active
*
*Severity Code Description Project File Line Suppression State
Error CS1061 'UserNotificationListener' does not contain a definition for 'GetNotifications' and no accessible extension method 'GetNotifications' accepting a first argument of type 'UserNotificationListener' could be found (are you missing a using directive or an assembly reference?) WindowsFormsApp7 C:\Users\stock\source\repos\WindowsFormsApp7\WindowsFormsApp7\Form2.cs 34 Active
*
*Severity Code Description Project File Line Suppression State
Error CS1061 'UserNotificationChangedEventArgs' does not contain a definition for 'Notification' and no accessible extension method 'Notification' accepting a first argument of type 'UserNotificationChangedEventArgs' could be found (are you missing a using directive or an assembly reference?) WindowsFormsApp7 C:\Users\stock\source\repos\WindowsFormsApp7\WindowsFormsApp7\Form2.cs 50 Active
*
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.UI.Notifications;
using Windows.UI.Notifications.Management;
namespace WindowsFormsApp7
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public async Task StartListeningAsync()
{
// Request access to the user's notifications
var accessStatus = await UserNotificationListener.Current.RequestAccessAsync();
if (accessStatus == UserNotificationListenerAccessStatus.Allowed)
{
// Get the user's notifications
var notifications = UserNotificationListener.Current.GetNotifications(NotificationKinds.Toast);
foreach (var notification in notifications)
{
// Process the notification
ProcessNotification(notification);
}
// Register for notifications when they are updated
UserNotificationListener.Current.NotificationChanged += OnNotificationChanged;
}
}
private void OnNotificationChanged(UserNotificationListener sender, UserNotificationChangedEventArgs args)
{
// Process the updated notification
ProcessNotification(args.Notification);
}
private void ProcessNotification(UserNotification notification)
{
// Do something with the notification
}
}
}
3 answers
Sort by: Most helpful
-
Castorix31 86,491 Reputation points
2022-12-15T07:55:39.27+00:00 -
Tolga TOPALOĞLU 26 Reputation points
2022-12-16T06:59:32.04+00:00 "C:\Program Files (x86)\Windows Kits\10\UnionMetadata[version]\Windows.winmd"
and
"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll"There are no dlls like they. How to donwload it? I'm on my school computer.
And there was an error says "You have to add a package for it." But I never understood it.
-
Tolga TOPALOĞLU 26 Reputation points
2022-12-16T07:54:22.687+00:00 I did and everything working fine now. I removed codes which one using AppInfo as you said and It's working fine now.