mardi 24 février 2015

Cannot access a disposed object from MdiControlStrip.GetTargetWindowIcon()

I generally understand exception Cannot access a disposed object. But this time it seems to be originating in non-user code. It occurrs occassionally when a form is closed. It looks like some automatic UI refresh is ongoing:



Message: Cannot access a disposed object.
Object name: 'Icon'.
HResult: -2146232798
HelpLink: (null)
Source: System.Drawing
TargetSite: IntPtr get_Handle()
StackTrace:
at System.Drawing.Icon.get_Handle()
at System.Drawing.Icon.get_Size()
at System.Drawing.Icon.ToBitmap()
at System.Windows.Forms.MdiControlStrip.GetTargetWindowIcon()
at System.Windows.Forms.MdiControlStrip..ctor(IWin32Window target)
at System.Windows.Forms.Form.UpdateMdiControlStrip(Boolean maximized)
at System.Windows.Forms.Form.UpdateToolStrip()
at System.Windows.Forms.Form.OnMdiChildActivate(EventArgs e)
at System.Windows.Forms.Form.ActivateMdiChildInternal(Form form)
at System.Windows.Forms.Form.WmMdiActivate(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
--end of stack trace--

It is possible this one is thrown only debugger session, I haven't seen it in production so far. (See the bottommost item of the stack trace.)




  • Is my assumption (that this is caused only by debugging session) correct? Or should I worry about the same problem in production?




  • Can this problem be somehow avoided?




Aucun commentaire:

Enregistrer un commentaire