Null Reference exception

Docking/MDI for Windows Forms Forum

Posted 14 years ago by Greg Shaffer - Boulder

I get this null reference exception. During a window closing, I activate a different window. Sometimes I get this exception, which does not give me very much information.

Any ideas of what could be happening here?


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

at ActiproSoftware.UIStudio.Dock.DocumentWindow.Activate()

at MAAD.Utilities.BaseApplication.BaseForm.dockManager_WindowClosing(Object sender, TabbedMdiWindowCancelEventArgs e)

at ActiproSoftware.UIStudio.Dock.DockManager.OnWindowClosing(TabbedMdiWindowCancelEventArgs e)

at ActiproSoftware.UIStudio.Dock.DockManager.ᐁ(TabbedMdiWindow[] , Boolean )

at ActiproSoftware.UIStudio.Dock.DockManager.ᐁ(TabStripButton )

at ActiproSoftware.UIStudio.Dock.TabbedMdiContainer.ᐁ(Object , CommandEventArgs )

at ActiproSoftware.UIStudio.TabStrip.TabStrip.OnCommand(CommandEventArgs e)

at ActiproSoftware.UIStudio.TabStrip.TabStrip.RaiseCommand(Command command)

at ActiproSoftware.UIStudio.TabStrip.TabStripButton.OnMouseUp(MouseEventArgs e)

at ActiproSoftware.WinUICore.UIElement.ActiproSoftware.WinUICore.IInputElement.RaiseMouseUpEvent(MouseEventArgs e)

at ActiproSoftware.WinUICore.UIControl.OnMouseUp(MouseEventArgs e)

at ActiproSoftware.UIStudio.TabStrip.TabStrip.OnMouseUp(MouseEventArgs e)

at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)

at System.Windows.Forms.Control.WndProc(Message& m)

at System.Windows.Forms.ScrollableControl.WndProc(Message& m)

at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)

at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)

at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Comments (5)

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Greg,

Do you have the latest build? Also, can you email us how to duplicate it in our sample app or come up with a project that duplicates it so we can debug it? Thanks!

Actipro Software Support

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
By the way, I had looked at the DocumentWindow.Activate code and the only thing that I can see that would cause that exception is if you had somehow removed the DockManager reference from the DocumentWindow. Could that have happened in your scenario?

Actipro Software Support

Posted 14 years ago by Greg Shaffer - Boulder

I don't have the time to modify the demo app at the moment. We're running version 1.0.0027.

As a workaround, I placed a try-catch around the Activate() function call. I will explore this more in the future when I have some time. I see it as non-critical.

And I looked around to see if we're explicitly setting the DockManager reference to null, and I didn't see anything. I will check with the debugger to see if the reference is null and get back to you.


[Modified at 06/15/2005 04:02 PM]
Posted 14 years ago by Greg Shaffer - Boulder

Here's what I found out... The DockManager reference is NULL.

The window I'm trying to activate appears to be the same window that is getting closed, however the memory chunk is different. It is as if the window getting passed into the TabbedMdiWindowCancelEventArgs is not the actual window, but a copy of some sort.

I used the function GetHashCode() to come to this conclusion. However, the key and most of the other properties are the same.

So, I cannot simply check like this:

if(windowToActivate != e.TabbedMdiWindow)

Instead I need to compare the keys or use some other mechanism.


I'm not sure if the problem is on my side or not, but that's what I found out.

Does that spark any ideas on your end?

Posted 14 years ago by Actipro Software Support - Cleveland, OH, USA
The only thing that can clear a DockManager reference in a DocumentWindow is the Dispose method. So something must be disposing the document window.

We dispose the document windows after close automatically if DockManager.DisposeDocumentWindowsAfterClose is set to true (default). If you are intending to close documents and then reopen the same instance without making a new document, you should turn that prop to false.

Does that help?

Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.