Krypton-Suite-Legacy-Archive / Krypton-NET-5.470

A update to Component factory's krypton toolkit to support the .NET 4.7 framework.
BSD 3-Clause "New" or "Revised" License
78 stars 20 forks source link

[BUG] ObjectDisposedException on ButtonSpecMdiChildMin #242

Closed tbolon closed 4 years ago

tbolon commented 4 years ago

We often capture errors from our application where the ButtonSpecMdiChildMin controls try to access the MdiChild property when the handle is destroyed/destroying.

System.ObjectDisposedException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Source  System.Windows.Forms
StackTrace     à System.Windows.Forms.Control.CreateHandle()
   à System.Windows.Forms.Form.CreateHandle()
   à System.Windows.Forms.Control.get_Handle()
   à ComponentFactory.Krypton.Toolkit.CommonHelper.IsFormMaximized(Form f)
   à ComponentFactory.Krypton.Ribbon.ButtonSpecMdiChildMin.GetVisible(IPalette palette)
   à ComponentFactory.Krypton.Toolkit.ButtonSpecView.UpdateVisible()
   à ComponentFactory.Krypton.Toolkit.ButtonSpecView..ctor(PaletteRedirect redirector, IPaletteMetric paletteMetric, PaletteMetricPadding metricPadding, ButtonSpecManagerBase manager, ButtonSpec buttonSpec)
   à ComponentFactory.Krypton.Ribbon.ButtonSpecManagerLayoutRibbon.CreateButtonSpecView(PaletteRedirect redirector, IPaletteMetric viewPaletteMetric, PaletteMetricPadding viewMetricPadding, ButtonSpec buttonSpec)
   à ComponentFactory.Krypton.Toolkit.ButtonSpecManagerBase.AddButtonSpec(ButtonSpec buttonSpec)
   à ComponentFactory.Krypton.Toolkit.ButtonSpecManagerBase.CreateFromCollection(ButtonSpecCollectionBase specs, Int32[]& nearCounts, Int32[]& farCounts)
   à ComponentFactory.Krypton.Toolkit.ButtonSpecManagerBase.CreateAll()
   à ComponentFactory.Krypton.Ribbon.KryptonRibbon.UpdateBackStyle()
   à ComponentFactory.Krypton.Ribbon.ViewLayoutRibbonTabsArea.OnRibbonFormDeactivate(Object sender, EventArgs e)
   à System.Windows.Forms.Form.OnDeactivate(EventArgs e)
   à ComponentFactory.Krypton.Toolkit.VisualForm.OnDeactivate(EventArgs e)
   à System.Windows.Forms.Form.set_Active(Boolean value)
   à System.Windows.Forms.Form.WmActivate(Message& m)
   à System.Windows.Forms.Form.WndProc(Message& m)
   à ComponentFactory.Krypton.Toolkit.VisualForm.WndProc(Message& m)
   à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   à System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

The method GetVisible from ButtonSpecMdiChildMin should check IsHandleCreated / IsDisposed before calling a method which will use the Handle property.