question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Toast throws exception on Windows

See original GitHub issue

Description

With the most recent updates Toast is now throwing an exception on Windows but works fine on the Mac. This is a simple mod to the standard Maui app that illustrates the problem. If you run this and set a breakpoint on the exception it stops when you press the button.

using CommunityToolkit.Maui.Alerts;
namespace TooltipsSample;

public partial class MainPage : ContentPage
{
	int count = 0;

	public MainPage()
	{
		InitializeComponent();
	}

	private void OnCounterClicked(object sender, EventArgs e)
	{
		count++;
        CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
        var toast = Toast.Make("Toast");
        try
        {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            toast.Show(cancellationTokenSource.Token);
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
        catch (Exception ex)
        {
            // This gives an exception on Windows
        }
 
        if (count == 1)
			CounterBtn.Text = $"Clicked {count} time";
		else
			CounterBtn.Text = $"Clicked {count} times";

		SemanticScreenReader.Announce(CounterBtn.Text);
	}
}

Steps to Reproduce

See the description for sample code.

Link to public reproduction project repository

https://github.com/dotnet/maui

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

I was not able test on other platforms

Affected platform versions

windows10.0.19041

Did you find any workaround?

use try/catch to not crash but Toast not working

Relevant log output

{"Could not load file or assembly 'Microsoft.Windows.AppNotifications.Builder.Projection, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.":"Microsoft.Windows.AppNotifications.Builder.Projection, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null"}

Issue Analytics

  • State:closed
  • Created 8 months ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mattleibowcommented, Jan 30, 2023

@jfversluis @brminnick is this a community toolkit issue?

0reactions
jfversluiscommented, Jan 30, 2023

This issue was moved to CommunityToolkit/Maui#946

Read more comments on GitHub >

github_iconTop Results From Across the Web

[WinRT]Resolving a ToastNotification Exception
My simple Windows notification application throws an exception with the error message "Access is denied." How can I fix this? PREFACE:
Read more >
Diagnosing and Resolving a ToastNotification Exception
My simple Windows notification application throws an exception with the error message "Access is denied." How can I fix this? PREFACE:
Read more >
An exception is thrown when invoking a toast notification ...
Hello,. In my ViewModel classes I have implemented the INotificationService to display toast notification.
Read more >
Unable to show toast notification. Falling back to original ...
I'm using the 3.9.2 version of the toolkit with the updated AppdeployToolkitConfig.xml and the Appdeploytoolkitmain.ps1 files (basically ...
Read more >
How I resolved WindowManager.BadTokenException for ...
Exception that is thrown when trying to add view whose LayoutParams LayoutParams#token is invalid. Lets, Look at the WindowManagerService. java file.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found