microsoft-ui-xaml
microsoft-ui-xaml copied to clipboard
FileOpenPicker, FolderPicker and FolderPicker not available in partial trust/AppContainer
Describe the bug
In WinUI 3 it is needed to do the following call to initialize a picker dialog:
WinRT.Interop.InitializeWithWindow.Initialize(openPicker, hWnd);
It works just fine in full trust mode but fails when it is called in partial trust/inside an AppContainer (access denied exception).
This is terrible news because it means that WinUI 3 can either use the WinRT file dialogs OR run in partial trust. But NOT both at the same time.
Steps to reproduce the bug
- Create a packaged WinUI 3 app with the default template
- Change
Package.appxmanifestsuch that the app runs in partial mode - Optional: add the
broadFileSystemAccesscapability - Test the FilePicker code snippet from the WinUI 3 Gallery: winui3gallery://item/FilePicker
Expected behavior
The file dialogs should open just as expected.
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.5.2: 1.5.240404000
Windows version
Windows 11 (22H2): Build 22621
Additional context
No response
Hi I'm an AI powered bot that finds similar issues based off the issue title.
Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!
Open similar issues:
- Webview2 cannot be created when a WinUI3.0 desktop app is built as partialTrust (#7982), similarity score: 0.74
Closed similar issues:
- FileOpenPicker, FileSavePicker, and FolderPicker break in WinUI3 Desktop (#2716), similarity score: 0.77
- Win32 picking APIs causes the UI to freeze after dialog closes (#8527), similarity score: 0.75
- Folder picker not working (#2973), similarity score: 0.74
- FileOpenPicker throw Invalid Window handle exception in Project Reunion 0.5 desktop app (#4519), similarity score: 0.73
Note: You can give me feedback by thumbs upping or thumbs downing this comment.
This issue is several years old and it looks like Microsoft simply does not want us to put non-UWP apps in AppContainer. Otherwise they would realize that most UI apps use file open/save pickers. AppContainer? yes, sure, but no file open/save. Very strange. Honestly, they should simply document this and not make developers waste their time.
@Rybasum The documentation part is kinda confusing. There is in-depth documentation on how to put your WPF, WinForms or WinUI 3 app into an AppContainer using MSIX. Yet something fundamental like selecting files isn't possible with Win32 or WinRT APIs.
I have a simple WinUI 3 app here where the user selects a file and more information is put into a DataGrid. You'd think that it would be a perfect candidate for partial trust/AppContainer and just the filesystem capability.
@sungaila you want to see
https://github.com/microsoft/WindowsAppSDK/issues/8#issuecomment-2256000803
and https://github.com/microsoft/WindowsAppSDK/issues/219
and the win32-app-isolation repo.