Skip to content

Commit bfdb352

Browse files
Leaf ShiLeaf Shi
authored andcommitted
Fix Control.Dispose crash when dependent UserControl fails to load due to missing assembly
1 parent 6bce8b5 commit bfdb352

File tree

1 file changed

+3
-3
lines changed
  • src/System.Windows.Forms/System/Windows/Forms

1 file changed

+3
-3
lines changed

src/System.Windows.Forms/System/Windows/Forms/Control.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4790,7 +4790,7 @@ protected override void Dispose(bool disposing)
47904790
}
47914791

47924792
// Unsubscribes from the Disposed event of the ContextMenuStrip.
4793-
if (ContextMenuStrip is ContextMenuStrip menu)
4793+
if (Properties?.TryGetValue(s_contextMenuStripProperty, out ContextMenuStrip? menu) == true)
47944794
{
47954795
menu.Disposed -= DetachContextMenuStrip;
47964796
}
@@ -4816,10 +4816,10 @@ protected override void Dispose(bool disposing)
48164816
SuspendLayout();
48174817
try
48184818
{
4819-
Properties.RemoveValue(s_ncAccessibilityProperty);
4819+
Properties?.RemoveValue(s_ncAccessibilityProperty);
48204820

48214821
DisposeAxControls();
4822-
Properties.GetValueOrDefault<ActiveXImpl>(s_activeXImplProperty)?.Dispose();
4822+
Properties?.GetValueOrDefault<ActiveXImpl>(s_activeXImplProperty)?.Dispose();
48234823

48244824
ResetBindings();
48254825

0 commit comments

Comments
 (0)