Page 1 of 1

Behavior.AssociatedObject in AttachableObject.OnDetaching is null (bug)

Posted: 03 Nov 2023, 17:35
by LizzyFox
Hi there!

If we use AssociatedObject in custom Behavior.OnDetaching method we get NullReferenceException :(
For example:
protected override void OnDetaching()
{
	base.OnDetaching();
	AssociatedObject.PreviewKeyDown -= OnPreviewKeyDown; // NullReferenceException
}
Noesis GUI version is 3.2.2, Unity version is 2023.1.13f1.

Thanks in advance.

Re: Behavior.AssociatedObject in AttachableObject.OnDetaching is null (bug)

Posted: 06 Nov 2023, 11:42
by sfernandez
Hi, this issue is already reported here: #2730.
It is happening because the associated object is being destroyed and then OnDetaching is called.
While we fix it, you can just check if the associated object is null before using it.