Skip to content

TaskScheduler_UnobservedTaskException after updating to v20.1.0 #2877

@IvanSadovskyi

Description

@IvanSadovskyi

Hello,

I have a WPF project (.NET 9) that worked well with Puppeteer until the latest update to v20.1.0. It still functions correctly, but if an HTML-to-PDF conversion is performed at least once, I get the following exception when closing the app:

A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Target closed (Session closed))

In my App.xaml.cs, I have the following code:

public App()
{
	TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
}

private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
	MessageBox.Show(e.Exception.Message);
	e.SetObserved();
}

This issue occurs only when the MainWindow has closing logic. Here’s my Window_Closing event handler:

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
	try
	{
		if (Tabs.Items.Count > 1)
		{
			var CloseWarning = new YesNo("Exit", "Are you sure you want to exit?")
			{
				Owner = this
			};
			CloseWarning.ShowDialog();
			if (!CloseWarning.Selected)
			{
				e.Cancel = true;
			}
		}
	}
	catch (Exception ex)
	{
		MessageBox.Show(ex.Message);
	}
}

However, even this simple closing event also causes the same exception:

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
	e.Cancel = true;
}

Downgrading to v20.0.5 fixed the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy