Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException in LayoutDocumentControl.OnModelChanged #240

Closed
Khaos66 opened this issue Feb 9, 2021 · 2 comments
Closed

NullReferenceException in LayoutDocumentControl.OnModelChanged #240

Khaos66 opened this issue Feb 9, 2021 · 2 comments

Comments

@Khaos66
Copy link
Contributor

Khaos66 commented Feb 9, 2021

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.

@Khaos66
Copy link
Contributor Author

Khaos66 commented Feb 10, 2021

@Dirkster99 I created a PR #241 for this issue. Please accept it and release a new version via Nuget. I'm stuck on this...

@Khaos66
Copy link
Contributor Author

Khaos66 commented Mar 19, 2021

Thank you for releasing a new Nuget <3

@Khaos66 Khaos66 closed this as completed Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant