From e436aa3bcb8594e58262e020c3dc7610d36af96a Mon Sep 17 00:00:00 2001 From: FVoronin Date: Sat, 3 Apr 2021 19:30:13 +0500 Subject: [PATCH 1/2] Do not throwing on InputBase.Dispose() if not in EditContext. --- src/Components/Web/src/Forms/InputBase.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Components/Web/src/Forms/InputBase.cs b/src/Components/Web/src/Forms/InputBase.cs index 8b00a57ffad4..336e34e842ae 100644 --- a/src/Components/Web/src/Forms/InputBase.cs +++ b/src/Components/Web/src/Forms/InputBase.cs @@ -187,6 +187,7 @@ protected string CssClass /// + [MemberNotNull(nameof(EditContext), nameof(CascadedEditContext))] public override Task SetParametersAsync(ParameterView parameters) { parameters.SetParameterProperties(this); @@ -315,7 +316,12 @@ protected virtual void Dispose(bool disposing) void IDisposable.Dispose() { - EditContext.OnValidationStateChanged -= _validationStateChangedHandler; + // When initialization in the SetParametersAsync method fails, the EditContext property can remain equal to null + if (EditContext != null) + { + EditContext.OnValidationStateChanged -= _validationStateChangedHandler; + } + Dispose(disposing: true); } } From c25ee4e1d4f17bb0e19fb521df93e5a7808b361f Mon Sep 17 00:00:00 2001 From: Pranav K Date: Sat, 3 Apr 2021 11:23:14 -0700 Subject: [PATCH 2/2] Update src/Components/Web/src/Forms/InputBase.cs --- src/Components/Web/src/Forms/InputBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Web/src/Forms/InputBase.cs b/src/Components/Web/src/Forms/InputBase.cs index 336e34e842ae..b8b2f298991a 100644 --- a/src/Components/Web/src/Forms/InputBase.cs +++ b/src/Components/Web/src/Forms/InputBase.cs @@ -317,7 +317,7 @@ protected virtual void Dispose(bool disposing) void IDisposable.Dispose() { // When initialization in the SetParametersAsync method fails, the EditContext property can remain equal to null - if (EditContext != null) + if (EditContext is not null) { EditContext.OnValidationStateChanged -= _validationStateChangedHandler; }