Hello,
I am using an Infragistics docking manager in my application. In this application I have support for saving layouts and loading them again during runtime. The problem I am having is when I'm disposing an old layout. Below follows a code snippet of what happens when the user has disposed an old layout and selected to create a new one. LayoutWorkspace is a class that inherits from DockableControlPane.
LayoutWorkspace layoutWorkspace = GenerateWorkspace();
layoutWorkspace.RootWorkItem = RootWorkItem;
layoutWorkspace.WorkspacePanel.Click += new EventHandler(OnLayoutWorkspace_Click);
layoutWorkspace.SetName(workspaceName);
layoutWorkspace.FlyoutSize = m_MainDockingArea.ActualSize;
layoutWorkspace.WorkspacePanel.BackColor = Color.White;
if (!m_DockingManager.DockAreas.Contains(m_MainDockingArea))
{
m_MainDockingArea = new DockAreaPane(DockedLocation.DockedLeft);
m_DockingManager.DockAreas.Add(m_MainDockingArea);
}
m_MainDockingArea.Panes.Add(layoutWorkspace);
When this code executes, the if block runs which means that m_MainDockingArea is newly created. My problem is that the last row: "m_MainDockingArea.Panes.Add(layoutWorkspace);" throws an exception saying that I'm trying to use a disposed object. The object mentioned is an old window form that was part of the OLD DockAreaPane. Do you have any idea why this might be happening? I should also mention that it only happens during some special constalation of windows ie. most layouts I have are disposed perfectly fine. I should also mention that we are using v8.2 of infragistic WinForms dlls.
As I found out later when trying to rearrange my code was that as long as I did Dispose on my Workspaces first before doing dispose on my windows I wasn't troubled with this exception when adding a new pane any longer. I am pretty sure that no renegade reference to m_MainDockingArea exists within our code, but it would seem that it is stuck somewhere deep inside the docking manager. I also found that the exception only occurred while having one tab in my layout. I.e. having two or zero tabs worked perfectly fine with my previously corrupt layout.
To me it would have been intuitive to do a dispose to the m_MainDockingArea in my clean up and just adding a new, but when I tested doing this things went really wrong and an area with a red cross appeared in my application. Moving the mouse over this area would crash the application.
Still, for now the issue seems solved. Thank you for your answer.
Regards, Johan
Hello Johan,
I am not sure I can understand what can cause this exception form the code snippet exposed in your post. It doesn’t actually show the creation of the LayoutWorkspace, you are probably adding some references to that object. What else can possibly cause this exception is that something else is referring the m_MainDockingArea and is releasing it “in some special constalation ”. It’s really hard to say what may be the reason for this exception before looking at a working project.
It might help to post more code describing the behavior of your application or better yet a sample project.
Here is some code that might prevent this without altering your logic:
m_DockingManager.DockAreas.Add(new DockAreaPane(DockedLocation.DockedLeft));
m_MainDockingArea = m_DockingManager.DockAreas[m_DockingManager.DockAreas.Count - 1];
m_DockingManager.DockAreas[m_DockingManager.DockAreas.Count-1].Panes.Add(layoutWorkspace);
Sincerely,
Petar Monov
Developer Support Engineer,
Infragistics, Inc
I am wondering, since there is no answer to any of the other threads as well, does the Infragistics team even read this forum?