Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to have this since you added it, but in the ordinary case, it's not very useful. The compiler cannot deduce the component lifecycle so so it's hard for it know these properties are not-null when executing any other method on a component.

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