NullReferenceException from ComboBox

  • Thread starter Thread starter Niall
  • Start date Start date
N

Niall

Our application is getting this exception out of the combo box's ChildWindow
class:

Exception Type: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: System.Windows.Forms
StackTrace: at System.Windows.Forms.ChildWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)


The ChildWindow object has a WeakReference back to the ComboBox. In some
cases, when the Callback is invoked, the ComboBox has already been garbage
collected. The error seems to be coming from the following code in
ChildWindow.Callback:

((ComboBox)ComboReference.Target).ChildWndProc(ref message);

Where ComboReference is the WeakReference back to the ComboBox. Because the
ComboBox has been collected, the code fails. There doesn't seem to be any
check on the WeakReference to ensure that it has not already been collected.

Does anyone know any more about this problem? Anyone know how to get around
it?

Thanks,

Niall
 
Back
Top