DockSiteLayoutSerializer.ApplyTo System.InvalidOperationException

Ribbon for WPF Forum

Posted 2 years ago by Patrick Neubauer
Version: 22.1.0
Platform: .NET 6.0
Environment: Windows 11 (64-bit)
Avatar

Hi there, 

we are facing a invalidOperationException when using the DockSizeLayoutSerializer.ApplyTo method. 
The exception message is : "Specified element is already the logical child of another element. Disconnect it first."
Is this a known problem?

Best regards 
Patrick

Comments (8)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Patrick,

We aren't aware of any issues with that.  Can you make a new simple sample project that shows the issue happening and send that to our support address, referencing this thread so that we debug it?  Please exclude the bin/obj folders from the .zip you send.  Thanks!


Actipro Software Support

Posted 2 years ago by Patrick Neubauer
Avatar

Does the stacktrace help you isolate the problem?

An exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll but was not handled in user code
Specified element is already the logical child of another element. Disconnect it first.

bei System.Windows.FrameworkElement.ChangeLogicalParent(DependencyObject newParent)
bei System.Windows.FrameworkElement.AddLogicalChild(Object child)
bei ActiproSoftware.Windows.Controls.Docking.Primitives.DockingWindowContainerBase.woM(Object , NotifyCollectionChangedEventArgs )
bei System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
bei System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
bei ActiproSoftware.Windows.Controls.Docking.Serialization.DockSiteLayoutSerializer.gvS(DockSite , XmlDockSiteLayout , DockHost , XmlToolWindowContainer , DockingWindowState )
bei ActiproSoftware.Windows.Controls.Docking.Serialization.DockSiteLayoutSerializer.Jvn(DockSite , XmlDockSiteLayout , XmlRaftingHost , DateTime )
bei ActiproSoftware.Windows.Controls.Docking.Serialization.DockSiteLayoutSerializer.OvG(DockSite , XmlDockSiteLayout )
bei ActiproSoftware.Windows.Controls.Docking.Serialization.DockSiteLayoutSerializer.ApplyTo(DockSite obj)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Patrick,

That stack shows that a ToolWindow or DocumentWindow is being added to a container, but it's already in the tree elsewhere.  We need to be able to debug through which exact control is already in the tree, and the scenario in which it happens in the first place, since that is not something that should be happening.  That's why we asked for a new simple sample project in the previous reply.  The stack trace, while helpful, doesn't allow us to isolate how to make this happen.


Actipro Software Support

Posted 2 years ago by Patrick Neubauer
Avatar

Hi there,

where do I need to look to identify the ToolWindow that is causing the issue? 
Do I need to look in the docksiteserializer or is the problem located in the docksitecontrol?

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Patrick,

If you use the VS debugger when the exception occurs, then you can probably look at which object is being added as a logical child.  I assume it's a docking window of some sort.  Then see what you think could contribute to it already being somewhere else. 

When restoring layouts, an earlier step in the DockSizeLayoutSerializer logic should have already reset the layout and removed any existing UI.  That's why it's odd that you are running into this.  Perhaps you have some code on your end related to serialization that is contributing to it?  Or it could be a bug on our end.  It's hard to say without having a simple project to debug.


Actipro Software Support

Posted 2 years ago by Patrick Neubauer
Avatar

I identified the docking window which is causing the exception. It´s a toolwindow that is a multi instance toolwindow.
Could this be the problem?

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Patrick,

Could you go into more detail about what you mean by a multi-instance tool window and how you are implementing that?  Keep in mind that a ToolWindow object is a visual and can only be in one location at a time.  Thus if you already have different ToolWindow control instances for each of these, then also be sure they have their own unique SerializationIds (e.g. "MyToolWindow1", "MyToolWindow2", etc.).  Otherwise if they have the same SerializationId, then it might be trying to reuse the same instance in two places.


Actipro Software Support

Posted 2 years ago by Patrick Neubauer
Avatar

I tried using unique SerializationIds but the problem still occurs. I will try to make a small sample demonstrating the problem.

The latest build of this product (v24.1.2) was released 0 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.