CommunityToolkit / WindowsCommunityToolkit

The Windows Community Toolkit is a collection of helpers, extensions, and custom controls. It simplifies and demonstrates common developer tasks building .NET apps with UWP and the Windows App SDK / WinUI 3 for Windows 10 and Windows 11. The toolkit is part of the .NET Foundation.
https://docs.microsoft.com/windows/communitytoolkit/
Other
5.89k stars 1.38k forks source link

ToastNotification run as admin will exception #4914

Open YiChunLin105062518 opened 1 year ago

YiChunLin105062518 commented 1 year ago

Describe the bug

In the standard user account, run app as admin, the app execution identity will be admin, resulting access is denied when prompt notification.

Regression

No response

Reproducible in sample app?

Steps to reproduce

1.loggin standard user account
2.run app as admin
3.the app call show toast:
new ToastContentBuilder()
.AddText(title)
.AddText(mag)
.Show();
4.toast not show and thrown exception:
[Exception in LogUnhandledException] exception: System.UnauthorizedAccessException: Access is denied. (0x80070005 (E_ACCESSDENIED))
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
   at ABI.Windows.UI.Notifications.IToastNotifierMethods.Show(IObjectReference _obj, ToastNotification notification)
   at Windows.UI.Notifications.ToastNotifier.Show(ToastNotification notification)
   at Microsoft.Toolkit.Uwp.Notifications.ToastNotifierCompat.Show(ToastNotification notification)
   at Microsoft.Toolkit.Uwp.Notifications.ToastContentBuilder.Show(CustomizeToast customize)
   at XXX.ToastHandler.<>c_DisplayClass11_0.<ShowToast>b_0()
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)

Expected behavior

notification to be prompted under the standard user account.

Screenshots

No response

Windows Build Number

Other Windows Build number

Windows 11 (22H2)

App minimum and target SDK version

Other SDK version

No response

Visual Studio Version

No response

Visual Studio Build Number

Microsoft Visual Studio Professional 2022 (64 bit) - Current version 17.5.4

Device form factor

Desktop

Nuget packages

Microsoft.Toolkit.Uwp.Notifications 7.1.2, 7.1.3

Additional context

No response

Help us help you

No.

ghost commented 1 year ago

Hello YiChunLin105062518, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

GitUser200607 commented 1 year ago

I've got the same error when running it using UAC. I think, the problem is the app trying to sent Toast notification to other account, not currently interactive one.

GitUser200607 commented 1 year ago

The solution of the same issue could be helpful: https://learn.microsoft.com/en-us/answers/questions/736896/(winrt)resolving-a-toastnotification-exception

ghost commented 1 year ago

This issue has been marked as "needs attention 👋" due to no activity for 15 days. Please triage the issue so the fix can be established.