Odd NullReferenceException with SaveToolWindowLayoutToFile

Docking/MDI for Windows Forms Forum

Posted 19 years ago by Boyd - Sr. Software Developer, Patterson Consulting, LLC
Before I try to track this issue down into a sample application, I thought I'd go ahead and post this to see if you know what's causing it.

I have a DockManager control that is located within a UserControl which is hosted in a ToolWindow controlled by a parent DockManager control... get all that? :) ... basically, it's just a DockManager instance in a ToolWindow.

When my application is shutting down, I save the DockManager layout of the instance in the ToolWindow prior to closing the ToolWindow. The following exception occurs when ToolWindow is not currently active:
See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at ᐛ.ᐁ(DockManager , XmlTextWriter )
   at ActiproSoftware.UIStudio.Dock.DockManager.SaveToolWindowLayoutToFile(String path)
   at ScriptEditor.ToolWindows.ObjectBrowser.OnApplicationClosing() in c:\visual studio projects\scripteditor\toolwindows\objectbrowser.cs:line 130
   at ActiproSoftware.UIStudio.Dock.DockManagerContainer.ShutdownDockManager() in C:\Visual Studio Projects\PattersonConsulting\Shared\ActiproSoftware\UIStudio.Dock.cs:line 114
   at ScriptEditor.MainForm.OnClosed(EventArgs e) in c:\visual studio projects\scripteditor\mainform.cs:line 234
   at System.Windows.Forms.Form.WmClose(Message& m)
   at System.Windows.Forms.Form.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)
If the ToolWindow is active when I shut down, everything works fine. It's only when the ToolWindow is not active that I have this problem. Any theories before I try to build this in a sample app? Just trying to save some time on my end if you think you might know what's causing it.

A little background about the call stack... the 'ShuddownDockManager' method is called from the 'OnClosing' method of my main application. It then calls an 'OnApplicationClosing' method for each loaded ToolWindow and DocumentWindow. It's the 'OnApplicationClosing' process that is trying to save the layout.


Comments (3)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
It's hard to tell what line in that method is throwing it without debugging a project however could it be that the HostContainerControl for the DockManager is set to null at the point you call this method? From looking at our code, that would cause an exception from the method in the stack trace.

Actipro Software Support

Posted 19 years ago by Boyd - Sr. Software Developer, Patterson Consulting, LLC
I'm e-mailing you a sample project...
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Thanks... found the problem with your project.

Actipro Software Support

The latest build of this product (v24.1.0) was released 4 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.