MDIParent + NullReferenceException: Object reference not set to an instance of an object

S

Sarang

Hi,

I have this code that makes the form as an MDIChild:

chartWindowController.GetForm().MdiParent =
_expertTradeMainFrm;
chartWindowController.GetForm().WindowState
=FormWindowState.Normal;
chartWindowController.GetForm().Show();

The above code snippet throws exception when Show() is called:

Message "Object reference not set to an instance of an object."

System.NullReferenceException: Object reference not set to an instance
of an object.
at System.Windows.Forms.ToolTip.CreateHandle()
at System.Windows.Forms.ToolTip.get_Handle()
at System.Windows.Forms.ToolTip.WmWindowPosChanging(Message& m)
at System.Windows.Forms.ToolTip.WndProc(Message& msg)
at
System.Windows.Forms.ToolTip.ToolTipNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SetFocus(HandleRef
hWnd)
at
System.Windows.Forms.ContainerControl.FocusActiveControlInternal()
at System.Windows.Forms.Form.set_Active(Boolean value)
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.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)

But when the same is not a MDIChild then it works fine i.e., if I
comment the line
chartWindowController.GetForm().MdiParent = _expertTradeMainFrm,
then
the application works fine.but ouptput is shown in independent window

I have Visual Team Edition 2005 for Developers + Windows XP Sp2.

Can anyone let me know what could be the reason or how to fix it.
Thanks in advance.

Regards
Sarang
 
M

Mr. Arnold

Sarang said:
Message "Object reference not set to an instance of an object."

System.NullReferenceException: Object reference not set to an instance
of an object.

It's a simple error message indication that's telling you that whatever
you're trying to use is not an Object and it has a NullReference pointer to
it.

In order to use an Object, it must be instantiated first most likely with
the New keyword or the Object was set to an existing Object.

Most likely, you're trying to use an Object in a form's code and it's simply
not there at the time you're trying to use it.
 
M

Marc Gravell

The fact that the failure is in CreateHandle() [having succesfully run
various other methods], and given that it only affects MDI, it isn't
as simple as that. I have actually been trying to debug something very
similar lately, and the web is littered with discussion of this...
feature.

In short; I don't think it is quite as simple as you suggest. But I
don't yet know the full cause... and I suspect it varies per issue
;-( The problem I am having, for instance, is highly sporadic; it
doesn't affect my machine at all, but a colleague on identical
hardware gets CreateHandle() errors regularly (but not repeatably) in
the MDI app.

Marc
 
M

Mr. Arnold

Marc Gravell said:
The fact that the failure is in CreateHandle() [having succesfully run
various other methods], and given that it only affects MDI, it isn't as
simple as that. I have actually been trying to debug something very
similar lately, and the web is littered with discussion of this...
feature.

In short; I don't think it is quite as simple as you suggest. But I don't
yet know the full cause... and I suspect it varies per issue ;-( The
problem I am having, for instance, is highly sporadic; it doesn't affect
my machine at all, but a colleague on identical hardware gets
CreateHandle() errors regularly (but not repeatably) in the MDI app.

I had a similar problem with a program that was running on a Citrix server
farm. The person who wrote the program had left and it fell to me to
support it. He got too fancy trying to make multiple forms run various parts
of the solution showing not showing on the forms, using multiple panels to
hold controls on forms.

It was a nightmare to support, with always object not set to an instance of
an object. Some days the piece of crap worked with no calls from a users,
then all of sudden, it would start blowing up. I cringed every time that VB
6 COM solution's name was mentioned.

I feel you pain.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top