Skip to content

Commit fb38da9

Browse files
authored
Do not throwing on InputBase.Dispose() if not in EditContext. (#31510)
* Do not throwing on InputBase.Dispose() if not in EditContext. Fixes #30990
1 parent d32b018 commit fb38da9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Components/Web/src/Forms/InputBase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ protected string CssClass
187187

188188

189189
/// <inheritdoc />
190+
[MemberNotNull(nameof(EditContext), nameof(CascadedEditContext))]
190191
public override Task SetParametersAsync(ParameterView parameters)
191192
{
192193
parameters.SetParameterProperties(this);
@@ -315,7 +316,12 @@ protected virtual void Dispose(bool disposing)
315316

316317
void IDisposable.Dispose()
317318
{
318-
EditContext.OnValidationStateChanged -= _validationStateChangedHandler;
319+
// When initialization in the SetParametersAsync method fails, the EditContext property can remain equal to null
320+
if (EditContext is not null)
321+
{
322+
EditContext.OnValidationStateChanged -= _validationStateChangedHandler;
323+
}
324+
319325
Dispose(disposing: true);
320326
}
321327
}

0 commit comments

Comments
 (0)