From 9528b1e2f192145b44fb7f7a17d80528810cfe8f Mon Sep 17 00:00:00 2001 From: Steven Rasmussen Date: Tue, 1 Apr 2025 06:46:35 -0600 Subject: [PATCH 1/3] Swallow the JSDisconnectedException when trying to call the 'dispose' Javascript method. --- src/Core/Components/InputFile/FluentInputFile.razor.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Core/Components/InputFile/FluentInputFile.razor.cs b/src/Core/Components/InputFile/FluentInputFile.razor.cs index 293d586514..91e1b1c615 100644 --- a/src/Core/Components/InputFile/FluentInputFile.razor.cs +++ b/src/Core/Components/InputFile/FluentInputFile.razor.cs @@ -429,7 +429,15 @@ public async ValueTask DisposeAsync() { if (_containerInstance != null) { - await _containerInstance.InvokeVoidAsync("dispose"); + try + { + await _containerInstance.InvokeVoidAsync("dispose"); + } + catch (JSDisconnectedException) + { + // Swallow. See: https://stackoverflow.com/questions/72488563/blazor-server-side-application-throwing-system-invalidoperationexception-javas + } + await _containerInstance.DisposeAsync(); } From aaedb4533fd53df90401606eb028184d2df1307f Mon Sep 17 00:00:00 2001 From: Steven Rasmussen Date: Tue, 1 Apr 2025 07:26:29 -0600 Subject: [PATCH 2/3] All items in dispose will fail if the circuit is closed. Wrap the try/catch around all items. --- .../InputFile/FluentInputFile.razor.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Core/Components/InputFile/FluentInputFile.razor.cs b/src/Core/Components/InputFile/FluentInputFile.razor.cs index 91e1b1c615..8218b5dafa 100644 --- a/src/Core/Components/InputFile/FluentInputFile.razor.cs +++ b/src/Core/Components/InputFile/FluentInputFile.razor.cs @@ -12,7 +12,7 @@ public partial class FluentInputFile : FluentComponentBase, IAsyncDisposable private ElementReference? _containerElement; private InputFile? _inputFile; private IJSObjectReference? _containerInstance; - + public static string ResourceLoadingBefore = "Loading..."; public static string ResourceLoadingCompleted = "Completed"; public static string ResourceLoadingCanceled = "Canceled"; @@ -427,23 +427,22 @@ private async Task UpdateProgressAsync(int percent, string title) // Unregister the drop zone events public async ValueTask DisposeAsync() { - if (_containerInstance != null) + try { - try + if (_containerInstance != null) { await _containerInstance.InvokeVoidAsync("dispose"); + await _containerInstance.DisposeAsync(); } - catch (JSDisconnectedException) + + if (Module != null) { - // Swallow. See: https://stackoverflow.com/questions/72488563/blazor-server-side-application-throwing-system-invalidoperationexception-javas + await Module.DisposeAsync(); } - - await _containerInstance.DisposeAsync(); } - - if (Module != null) + catch (JSDisconnectedException) { - await Module.DisposeAsync(); + // Swallow. See: https://stackoverflow.com/questions/72488563/blazor-server-side-application-throwing-system-invalidoperationexception-javas } } } From 9daaec0a09ceecc89490ee989dda5f2d3796838a Mon Sep 17 00:00:00 2001 From: Steven Rasmussen Date: Tue, 1 Apr 2025 09:22:38 -0600 Subject: [PATCH 3/3] Updated per comments. --- .../Components/InputFile/FluentInputFile.razor.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Core/Components/InputFile/FluentInputFile.razor.cs b/src/Core/Components/InputFile/FluentInputFile.razor.cs index 8218b5dafa..cf9cdf1229 100644 --- a/src/Core/Components/InputFile/FluentInputFile.razor.cs +++ b/src/Core/Components/InputFile/FluentInputFile.razor.cs @@ -429,20 +429,22 @@ public async ValueTask DisposeAsync() { try { - if (_containerInstance != null) + if (_containerInstance is not null) { await _containerInstance.InvokeVoidAsync("dispose"); - await _containerInstance.DisposeAsync(); + await _containerInstance.DisposeAsync().ConfigureAwait(false); } if (Module != null) { - await Module.DisposeAsync(); + await Module.DisposeAsync().ConfigureAwait(false); } } - catch (JSDisconnectedException) + catch (Exception ex) when (ex is JSDisconnectedException || + ex is OperationCanceledException) { - // Swallow. See: https://stackoverflow.com/questions/72488563/blazor-server-side-application-throwing-system-invalidoperationexception-javas + // The JSRuntime side may routinely be gone already if the reason we're disposing is that + // the client disconnected. This is not an error. } } }