Skip to content

NullReferenceException in LayoutDocumentControl.OnModelChanged #240

@Khaos66

Description

@Khaos66

Hi, when I use Drag&Drop to move a document and dock it in a new panel a NullReferenceException is thrown in OnModelChanged.

It seems that the line SetLayoutItem(Model.Root.Manager.GetLayoutItemFromModel(Model)); is the problem. The debugger shows that Model.Root is null. The CallStack is quite long:

AvalonDock.dll!AvalonDock.Controls.LayoutDocumentControl.OnModelChanged(System.Windows.DependencyPropertyChangedEventArgs e) Line 52	C#
AvalonDock.dll!AvalonDock.Controls.LayoutDocumentControl.OnModelChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) Line 43	C#
[...]
AvalonDock.dll!AvalonDock.DockingManager.InternalRemoveLogicalChild(object element) Line 1441	C#
AvalonDock.dll!AvalonDock.Controls.LayoutFloatingWindowControl.FloatingWindowContentHost.DestroyWindowCore(System.Runtime.InteropServices.HandleRef hwnd) Line 137	C#
[...]
AvalonDock.dll!AvalonDock.Controls.LayoutFloatingWindowControl.OnClosed(System.EventArgs e) Line 536	C#
AvalonDock.dll!AvalonDock.Controls.LayoutDocumentFloatingWindowControl.OnClosed(System.EventArgs e) Line 150	C#
[...]

As you can see the method LayoutDocumentFloatingWindowControl.OnClosed is called before the OnModelChanged.
There the Root is disposed before the window is closed:

ILayoutRoot root = Model.Root;
if (root != null)
{
	root.Manager.RemoveFloatingWindow(this);
	root.CollectGarbage();
}
if (_overlayWindow != null)
{
	_overlayWindow.Close();
	_overlayWindow = null;
}
base.OnClosed(e);
[...]

Not sure why this is only a problem in my project. But looks logical to me, that a NullReferenceException is thrown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions