Open
Description
Describe the bug
I am trying to open a File Picker but it works only if I am not using the app in elevation mode.
I'm getting the following error:
System.Runtime.InteropServices.COMException: 'Error HRESULT E_FAIL has been returned from a call to a COM component.'
The error appears when the code tries to execute the following line of code:
var file = await picker.PickSingleFileAsync();
Steps to reproduce the bug
- Create a WASDK app using version 1.4.2 and .NET 7
- Create an extension method so you can get the Window Handle
AppWindowExtension.cs
public static IntPtr GetHandle(this Microsoft.UI.Xaml.Window window)
{
return WinRT.Interop.WindowNative.GetWindowHandle(window);
}
- Make the MainWindow available outside the App class
App.xaml.cs
public static Window MainWindow { get; private set; }
- Use the generated Button_Click event method to open the File Picker
MainWindow.xaml.cs
var picker = new FileOpenPicker();
picker.FileTypeFilter.Add("*");
InitializeWithWindow.Initialize(picker, App.MainWindow.GetHandle());
var file = await picker.PickSingleFileAsync();
- Build the app and try to Run as Administrator (it's not neccesary to configure elevation, just right click on the app works)
- Click the button to open the File Picker
- The app will crash :(
Expected behavior
I would expect this basic feature of picking a file to work even if I run the app as admin.
My app has a lot of features that require elevation so getting rid of elevation is not an option for me.
Screenshots
No response
NuGet package version
1.4.2
Packaging type
Packaged (MSIX)
Windows version
Insider Build (xxxxx) (only on Windows 11)
IDE
Visual Studio 2022
Additional context
The same for FolderPicker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment