Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TaskScheduler_UnobservedTaskException after updating to v20.1.0 #2877

Open
Waexu opened this issue Feb 6, 2025 · 3 comments · May be fixed by #2878
Open

TaskScheduler_UnobservedTaskException after updating to v20.1.0 #2877

Waexu opened this issue Feb 6, 2025 · 3 comments · May be fixed by #2878

Comments

@Waexu
Copy link

Waexu commented Feb 6, 2025

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.

@jorrit
Copy link

jorrit commented Feb 6, 2025

Same here. Could have been caused by #2824.

The exception loaded in task _closeTaskCompletionSource is only read by WaitForNetworkIdleAsync(), which I do not invoke in my code.

@kblok kblok linked a pull request Feb 6, 2025 that will close this issue
@kblok
Copy link
Member

kblok commented Feb 6, 2025

Can anyone see if the revert fixes it?
#2878

@Waexu
Copy link
Author

Waexu commented Feb 9, 2025

e4b3f3a is not compilable and contains many errors. I'm not familiar with the PuppeteerSharp source code, so I can't really check until I have a compilable commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants