Skip to content

Commit

Permalink
Do not throwing on InputBase.Dispose() if not in EditContext. (#31510)
Browse files Browse the repository at this point in the history
* Do not throwing on InputBase.Dispose() if not in EditContext.

Fixes #30990
  • Loading branch information
fvoronin authored Apr 3, 2021
1 parent d32b018 commit fb38da9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Components/Web/src/Forms/InputBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ protected string CssClass


/// <inheritdoc />
[MemberNotNull(nameof(EditContext), nameof(CascadedEditContext))]
public override Task SetParametersAsync(ParameterView parameters)
{
parameters.SetParameterProperties(this);
Expand Down Expand Up @@ -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 is not null)
{
EditContext.OnValidationStateChanged -= _validationStateChangedHandler;
}

Dispose(disposing: true);
}
}
Expand Down

0 comments on commit fb38da9

Please sign in to comment.