From 0ede15f3a8918eadae2827e7d66c3e6789f256d7 Mon Sep 17 00:00:00 2001 From: Umair Tahir Date: Mon, 27 Jan 2025 10:49:17 +0500 Subject: [PATCH 1/3] Fixed ObjectDisposedException in Blazor Web App (InteractiveWebAssembly to StreamRendering mode) Added a try-catch block around the InvokeVoidAsync method call to handle potential ObjectDisposedException exceptions. This ensures graceful handling of scenarios where the JavaScript runtime might not be available, such as in a hybrid Blazor Web App environment. The catch block includes a comment explaining that no action is needed if this exception occurs. --- src/Blazored.Modal/BlazoredModal.razor | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Blazored.Modal/BlazoredModal.razor b/src/Blazored.Modal/BlazoredModal.razor index fe16c9d0..a733dc10 100644 --- a/src/Blazored.Modal/BlazoredModal.razor +++ b/src/Blazored.Modal/BlazoredModal.razor @@ -146,8 +146,15 @@ _haveActiveModals = false; if (_styleFunctions is not null) { + try + { await _styleFunctions.InvokeVoidAsync("removeBodyStyle"); } + catch (ObjectDisposedException) + { + // If the we're working in hybrid scenario for Blazor Web App, where JsRuntime is not available, we don't need to do anything + } + } } async ValueTask IAsyncDisposable.DisposeAsync() From 39629150213ecd89f35b1c3f0a96e8d020edb2e3 Mon Sep 17 00:00:00 2001 From: Umair Tahir Date: Mon, 27 Jan 2025 10:51:42 +0500 Subject: [PATCH 2/3] Refactor ClearBodyStyles method for better readability Moved the try-catch block inside the if statement checking for non-null _styleFunctions. This ensures the try block is only executed when _styleFunctions is available and handles ObjectDisposedException in the same context, improving code structure and readability. --- src/Blazored.Modal/BlazoredModal.razor | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Blazored.Modal/BlazoredModal.razor b/src/Blazored.Modal/BlazoredModal.razor index a733dc10..5f6b2666 100644 --- a/src/Blazored.Modal/BlazoredModal.razor +++ b/src/Blazored.Modal/BlazoredModal.razor @@ -146,15 +146,15 @@ _haveActiveModals = false; if (_styleFunctions is not null) { - try - { - await _styleFunctions.InvokeVoidAsync("removeBodyStyle"); + try + { + await _styleFunctions.InvokeVoidAsync("removeBodyStyle"); + } + catch (ObjectDisposedException) + { + // If the we're working in hybrid scenario for Blazor Web App, where JsRuntime is not available, we don't need to do anything + } } - catch (ObjectDisposedException) - { - // If the we're working in hybrid scenario for Blazor Web App, where JsRuntime is not available, we don't need to do anything - } - } } async ValueTask IAsyncDisposable.DisposeAsync() From 8400138be57342bb8658efbfcc62dec770e06132 Mon Sep 17 00:00:00 2001 From: Umair Tahir Date: Wed, 30 Jul 2025 17:33:08 +0500 Subject: [PATCH 3/3] Update target framework to .NET 9.0 This commit updates the project's target framework from .NET 8.0 to .NET 9.0, ensuring compatibility with the latest features and improvements. --- src/Blazored.Modal/Blazored.Modal.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Blazored.Modal/Blazored.Modal.csproj b/src/Blazored.Modal/Blazored.Modal.csproj index c7ef3eeb..63bdf377 100644 --- a/src/Blazored.Modal/Blazored.Modal.csproj +++ b/src/Blazored.Modal/Blazored.Modal.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable