Crash while running NSAlert.runModal

My application overrides AppDelegate.menuWillOpen(). During startup of the application (in AppDelegate.applicationDidFinishLaunching) I attempt to install a privileged helper tool using SMAppService. On detecting that the tool needs to be allowed/installed I open the Login Items & Extensions settings and then display a modal dialog, advising the user to authorise the privileged helper. Then the application crashes with a message in the crash file

Application Specific Information: BUG IN CLIENT OF LIBDISPATCH: trying to lock recursively

Maybe I could avoid this by removing the menuWillOpen() override so am looking for a workaround. i.e. is it possible to install the override function programmatically later during initialisation, rather then declaring it in an extension.

I have attached the crash log.

To help clarify the above, the menuWillOpen() function is declared as an AppDelegate:NSMenuDelegate extension.

extension AppDelegate: NSMenuDelegate {
	func menuWillOpen(_ menu: NSMenu)
	{
		if menu == myMenu {
			// enable/disable menu items
		}
	}
}

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var myMenu: NSMenu!
// NSApplicationDelegate functions
}

Where and how do you call NSAlert?

Crash while running NSAlert.runModal
 
 
Q