Skip to content

In .net 9 blazor wasm mode, unhandled exceptions in asynchronous methods will cause the Runtime to crash #59007

Closed
@dashiell-zhang

Description

@dashiell-zhang

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In .net 9 blazor wasm mode, unhandled exceptions in asynchronous methods will cause the Runtime to crash

In .net 9, if the method is asynchronous and an unhandled exception is returned, the entire blazor wasm .net runtime will crash directly. After the crash, clicking on any interface will be invalid, and only error messages will continue to be output. And this crash cannot be captured by ErrorBoundary.

When an unhandled exception is generated in a non-asynchronous method, it will not crash.

As shown in the following two codes

@page "/counter"

<PageTitle>Counter</PageTitle>

<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

<button class="btn btn-primary" @onclick="IncrementCountBug">Click me Bug</button>

@code {
    private int currentCount = 0;

    private  void IncrementCount()
    {
        currentCount++;

        if (currentCount == 3)
        {
            throw new Exception("NEW BUG");
        }
    }


    private async void IncrementCountBug()
    {
        await Task.Delay(1);

        currentCount++;

        if (currentCount == 3)
        {
            throw new Exception("NEW BUG");
        }
    }
}

1.mp4
2.mp4

When an exception occurs in the IncrementCount method, it will simply throw an exception, but this will not affect subsequent operations. However, when the IncrementCountBug throws an exception, it will directly cause the entire runtime to crash, and any subsequent button clicks will not work.

After switching to .net 6 .net 7 .net 8, the IncrementCountBug method will not cause a crash. This only happens in .net 9.

There is a test later that changes private async void IncrementCountBug() to private async Task IncrementCountBug() and the crash will not occur. So the conclusion is that if an unhandled exception is thrown in async void, it will directly cause the .net 9 wasm runtime to crash.

https://github.com/dashiell-zhang/BlazorAppTempIssues.git

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

9.0.100

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions