From c880db58bfd3d348fc9e783c4f65691b9801639d Mon Sep 17 00:00:00 2001 From: George Drak Date: Fri, 13 Oct 2023 14:44:58 +0500 Subject: [PATCH] fix(blazor): remove sync dispose --- .../Components/BaseComponent.cs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/Sitko.Core.Blazor/Components/BaseComponent.cs b/src/Sitko.Core.Blazor/Components/BaseComponent.cs index d2f02c5d4..7bd8a1221 100644 --- a/src/Sitko.Core.Blazor/Components/BaseComponent.cs +++ b/src/Sitko.Core.Blazor/Components/BaseComponent.cs @@ -15,7 +15,7 @@ public interface IBaseComponent Task NotifyStateChangeAsync(); } -public abstract class BaseComponent : ComponentBase, IAsyncDisposable, IDisposable +public abstract class BaseComponent : ComponentBase, IAsyncDisposable { private static readonly FieldInfo? RenderFragment = typeof(ComponentBase).GetField("_renderFragment", BindingFlags.NonPublic | BindingFlags.Instance); @@ -120,29 +120,18 @@ public async ValueTask DisposeAsync() if (!isDisposed) { NavigationManager.LocationChanged -= HandleLocationChanged; + Dispose(true); + await DisposeAsync(true); if (scope is not null) { await scope.Value.DisposeAsync(); } - Dispose(true); - await DisposeAsync(true); isDisposed = true; GC.SuppressFinalize(this); } } - public void Dispose() - { - if (!isDisposed) - { - throw new InvalidOperationException( - "This class must not be disposed synchronously. This method only here to avoid exception on sync scope dispose in .NET 5"); - } - - GC.SuppressFinalize(this); - } - public override string ToString() => $"{GetType().Name} {ComponentId}"; public Task NotifyStateChangeAsync() => InvokeAsync(StateHasChanged); @@ -334,4 +323,3 @@ public enum ScopeType { Parent = 0, Isolated = 1 } -