diff --git a/src/System.Windows.Forms/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/System/Windows/Forms/Control.cs index 9253cce66ec..7441da6fe06 100644 --- a/src/System.Windows.Forms/System/Windows/Forms/Control.cs +++ b/src/System.Windows.Forms/System/Windows/Forms/Control.cs @@ -4790,7 +4790,7 @@ protected override void Dispose(bool disposing) } // Unsubscribes from the Disposed event of the ContextMenuStrip. - if (ContextMenuStrip is ContextMenuStrip menu) + if (Properties?.TryGetValue(s_contextMenuStripProperty, out ContextMenuStrip? menu) == true) { menu.Disposed -= DetachContextMenuStrip; } @@ -4816,10 +4816,10 @@ protected override void Dispose(bool disposing) SuspendLayout(); try { - Properties.RemoveValue(s_ncAccessibilityProperty); + Properties?.RemoveValue(s_ncAccessibilityProperty); DisposeAxControls(); - Properties.GetValueOrDefault(s_activeXImplProperty)?.Dispose(); + Properties?.GetValueOrDefault(s_activeXImplProperty)?.Dispose(); ResetBindings();