Cannot create instance of NSSavePanel

I've recently migrated my MacOS app to deployment target 12.0 and when I try to create an instance of NSSavePanel, like this:

let panel = NSSavePanel()

I get the following error:

2023-02-07 18:11:49.362237+0100 Acsy[31010:8797816] [miscellany] CLIENT ERROR: remote view delegate NSSavePanel lacks method which can react to the details of Error Domain=NSCocoaErrorDomain Code=4097 "connection to service created from an endpoint" UserInfo={NSDebugDescription=connection to service created from an endpoint} 2023-02-07 18:11:49.362584+0100 Acsy[31010:8797816] [OpenSavePanels] Unable to display save panel (unrecognized error: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service created from an endpoint" UserInfo={NSDebugDescription=connection to service created from an endpoint})

Any ideas what this means?

This used to work MacOS 11.5.

I'm on Xcode 14.1 / Ventura 13.0

entitlements: com.apple.security.files.user-selected.read-write is set to true

Can you add a bit more context? e.g., the whole code snippet where you try to instantiate the object

It's sad that SwiftUI doesn't have an equivalent for Open/Save panels. Online docs suggest using Apple's doc interface, but that doesn't apply to all apps. I've had this issue for ≈18 months, still unresolved.

I'm fairly certain it's related to entitlements and possible App Groups. I'm now getting :

[OpenSavePanels] Unable to display save panel (unrecognized error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service created from an endpoint was invalidated from this process." UserInfo={NSDebugDescription=The connection to service created from an endpoint was invalidated from this process.})

The issue is reproducable when creating a new project with storyboards in xcode 14.2. OS version is irrelevant. Fails in all. Also instantiation of NSOpenPanel gives the same error. creating a new project with SwiftUI works, with storyboards fails.

I get this same error some of the time in a MacOS app I am writing. Running macOS Catalina Version 10.15.7 Xcode 11.3.1

    let panel = NSOpenPanel()
    panel.canChooseDirectories = true
    panel.canChooseFiles = false
    panel.allowsMultipleSelection = false
    panel.resolvesAliases = true
    let result = panel.runModal()
    if result == NSApplication.ModalResponse.OK { ... }

Something is suspicious, because I can get similar issues on other 3rd party programs I have built. I am running an older version of macOS, because I am slow to update all my software (about a days worth of work and usually a lot of breakage).

In my case I solved the issue. The issue was related to a bundle Id of an app I have in the AppStore. Using that specific bundle Id in any app with NSOpenPanel (or NSSavePanel) resulted inthe error. Replace the bundle Id in the same project with another one and the problem goes away. Why? Some caching issue of XCode. Cleaning the build folder did not help. So I did a full uninstall and removal of all directories related to XCode. Then reinstalled XCode. No more problem. I'm thinking perhaps an outdated entry TCC.db?

Cannot create instance of NSSavePanel
 
 
Q