-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Description
Description
The Blazor JS Interop page contains the following example of disposing a JS Module:
async ValueTask IAsyncDisposable.DisposeAsync()
{
if (module is not null)
{
await module.DisposeAsync();
}
}
However, this can lead to an unhandled exception being thrown (noticeable in the debugger, even if it's silent elsewhere).
This has been reported before: In this issue dotnet/aspnetcore#38822 Steve Sanderson said:
This is as designed. The exception here is JSDisconnectedException, indicating that the JS interop call cannot be issued because there's no active connection. In this case you probably want to ignore such exceptions, so you should use a try/catch for that specific exception type in this place.
To me, this implies that the code example on the doc page should look more like this:
async ValueTask IAsyncDisposable.DisposeAsync()
{
if (module is not null)
{
try
{
await module.DisposeAsync();
}
catch (JSDisconnectedException)
{
}
}
}
I'd imagine that it's not the intention that example code should throw unhandled exceptions.
Page URL
Content source URL
Document ID
49fa31d8-72a6-01a1-027d-6edeac9e0fc4
Article author
Metadata
Metadata
Assignees
Labels
Type
Projects
Status